AndroidAnnotations + Instant App - 找不到生成的 <applicationId>.R class

AndroidAnnotations + Instant App - The generated <applicationId>.R class cannot be found

我目前正在使用 android-topeka 示例项目开发 Android 即时应用程序。

在我的 Activity:

上使用 AndroidAnnotations 后,一切正常
@EActivity(resName = "activity_start")
public class StartActivity extends AppCompatActivity {
...
}

如果我想启动 application(:installed) 一个,一切正常,但对于 instant-app (:instant),我收到以下错误:

:base:javaPreCompileDebugFeature UP-TO-DATE
error: The generated <applicationId>.R class cannot be found
1 error
:base:compileDebugFeatureJavaWithJavac FAILED

附加信息:

If I remove the application project(':installed') in the base build.gradle I can start the instant-app but with the wrong application-id (configured in the :installed project).

基于此SO related post:

当您修改 applicationId 时会发生此错误。示例中提供的脚本假定您已声明 android.defaultConfig.applicationId。如果未声明,则该值为 null 或生成 null.R.

defaultConfig {

    // Rest of Config

    javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["resourcePackageName": "<Original Package Name>"]
            }
    }
}

注意:原来的Package Name应该和R在你activity的位置相同。

在这个 issue 跟踪器的帮助下,我终于明白了(感谢 Kay-Uwe Janssen)。也感谢杰斯。总体而言,它是结合了 Manifest Finder 和 annotationProcessorOptions.

的设置

这是我的 gradle/Manifest 设置的样子:

基地:

build.gradle:

android {
    ...

    baseFeature true

    defaultConfig {
        ...

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["resourcePackageName": "com.test.base"]
            }
        }
    }

    buildTypes {
        release {
        }
    }
}
dependencies {
    application project(':installed')
    ...
}

AndroidManifest.xml:

<manifest ...
    package="com.test.base">
    ...
</manifest>

已安装:

build.gradle:

android {
      ...
}

dependencies {
    implementation project(':base')
}

AndroidManifest.xml:

<manifest package="com.test2">
</manifest>

即时:

build.gradle:

android {
    defaultConfig {}
}

dependencies {
    implementation project(':base')
}

With this setup, the Instant App has the same App-Id as the Installed one "com.test2"