简体   繁体   中英

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

I'm currently working on Android instant apps by using the android-topeka example project.

Everything works as expected, after I'm using AndroidAnnotations on my Activity:

@EActivity(resName = "activity_start")
public class StartActivity extends AppCompatActivity {
...
}

If I want to start the application ( :installed ) one, everything works, but for the instant-app ( :instant ), I get the following error:

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

Additional Info:

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).

Finally I got it, by the help of this issue tracker (thx to Kay-Uwe Janssen). Also thx to jess. Overall it was the setup combined with the Manifest Finder and the annotationProcessorOptions .

This is how my gradle/Manifest setup looks like:

Base:

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>

Installed:

build.gradle:

android {
      ...
}

dependencies {
    implementation project(':base')
}

AndroidManifest.xml:

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

Instant:

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"

Based from this SO related post :

This error happens when you modify the applicationId . The script provided in example assumes that you have declared android.defaultConfig.applicationId . If this was not declared, the value will be null or it generates null.R .

 defaultConfig { // Rest of Config javaCompileOptions { annotationProcessorOptions { arguments = ["resourcePackageName": "<Original Package Name>"] } } }

Note: Original Package Name should be same as the location of R in you activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM