Android Annotations + multiple paths to APT

2019-06-14 02:35发布

问题:

imagine some proyect like this one that use android-annotations and for this work i have to put this in build.gradle

apt {
    arguments {
        resourcePackageName "com.pandaos.smartconfig"
        androidManifestFile variant.outputs[0].processResources.manifestFile
    }
}

where: resourcePackageName "com.pandaos.smartconfig"

its the path where code its annotated... the config for plugin android-apt

apply plugin: 'com.neenbedankt.android-apt'

I suppose, that plugin "invoke" some task to generate the code that android-annotations create under the hood, but...

Its possible define multiple "packages in the app"?

回答1:

The resourcePackageName comes from the configuration option for AndroidAnnotations as mentioned here:

By default, AndroidAnnotations try to find the R class by extracting application package from AndroidManifest.xml file. But in some cases you may want to specify a custom package to look for the R class. This is why we added resourcePackageName option.

There are two things to note:

  1. The option refers to the Android package name, which does not have to be the same as your java package name.

  2. The R package name can be different from the Android package name you set in AndroidManifest.xml if you use the applicationId option in the Gradle build file.

It's totally fine to have a different java package name in your code. AFAIK this will not influence AndroidAnnotations in any way.

The apt block is provided by the android-apt plugin and allows you to configure any parameter to annotation processors in your project. In this case it configures the parameters that AndroidAnnotations need to do its job. The android-apt plugin serves two purposes in this case: it configures the parameters for the AndroidAnnotations processor, and it will make sure you can reference the sources that are generated by AA in Android Studio.