Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Cannot pass resourcePackageName to new annotationProcessor #1964

Description

@AleksanderMielczarek

Hi,

apt plugin is not compatible with Gradle build tools 2.3.0 so I've switched to annotationProcessor and used approach suggested here.

I have two different applicationId based on flavor. I cannot build flavor dev. AA is looking in wrong package (should use "com.my.app" but instead "com.my.app.debug" is used). Flavor prod, which has default applciationId works. This setup works with apt and 2.2.3 tools.

I think resourcePackageName is not passed properly to AA.

Log:

14:23:45.477 [Daemon worker Thread 23] ERROR o.a.i.r.ProjectRClassFinder:47 - The generated com.my.app.debug.R class cannot be found`

build.gradle:

apply plugin: 'com.android.application'

android {
 
    defaultConfig {
        applicationId "com.my.app"   
    }

    productFlavors {    
        dev {
            applicationId "com.my.app.debug"           
        }
        prod {
            applicationId "com.my.app"           
        }
    }
}

android.applicationVariants.all { variant ->
    variant.variantData.variantConfiguration.javaCompileOptions.annotationProcessorOptions.arguments =
            ['androidManifestFile': variant.outputs[0]?.processResources?.manifestFile?.absolutePath,
             'resourcePackageName': android.defaultConfig.applicationId]
}

Activity

  1. qhutch commented on Mar 7, 2017

    @qhutch

    Hi @AleksanderMielczarek, I have the same problem, did you manage to find a solution to compile your app in debug ?

  2. dodgex commented on Mar 7, 2017

    @dodgex
    Member

    Hey guys, I'm going to test this with my app if i can reproduce - and hopefully fix this issue.

  3. dodgex commented on Mar 7, 2017

    @dodgex
    Member

    @AleksanderMielczarek

    apt plugin is not compatible with Gradle build tools 2.3.0 so I've switched to annotationProcessor and used approach suggested here.

    why do you think that it is not compatible? I just updated build tools to 2.3.0 and gradlew to 3.3 and with android-apt 1.8 i can build my app. even when i add product flavours.

    can you supply a sample project where you have this issue so that i can see if i can reproduce it? :)

  4. AleksanderMielczarek commented on Mar 7, 2017

    @AleksanderMielczarek
    Author

    @dodgex I get message about incompatibility in quite big project which I'm unable to paste here but I'll prepare example project and let you know.

  5. couchcrew-thomas commented on Mar 8, 2017

    @couchcrew-thomas

    @dodgex : android-apt is now officially deprecated: https://bitbucket.org/hvisser/android-apt/wiki/Migration
    So androidannotations should be made compatible with the new annotationProcessor.

  6. couchcrew-thomas commented on Mar 8, 2017

    @couchcrew-thomas

    I've created a sample project showing that android-apt is now incompatible with google plugins like databinding.

    If you try to compile it fails.
    When you remove the line apply plugin: 'android-apt' it compiles fine.

    As you can see, I did not even add androidannotations. android-apt is deprecated since 2.3 canary came out and since current and future google plugins will rely on the new annotation processor, androidannotations should use it as well.
    AATest.zip

  7. AleksanderMielczarek commented on Mar 8, 2017

    @AleksanderMielczarek
    Author

    @couchcrew-thomas I'am using databinding so that would be the reason why build fails for me.

  8. dodgex commented on Mar 8, 2017

    @dodgex
    Member

    @couchcrew-thomas thank you for that information. I didn't know that.

    I'll see what I can do to get the stuff working. I just wonder why my app is building fine with 2.3 and android-apt. Maybe because I'm not using stuff like databinding.

  9. AleksanderMielczarek commented on Mar 8, 2017

    @AleksanderMielczarek
    Author
  10. dodgex commented on Mar 9, 2017

    @dodgex
    Member

    @AleksanderMielczarek Thank you for that project. I think I found a solution. 🎉

    As we have implemented some code that automatically finds the AndroidManifest.xml it is no longer necessary to provide the path in build.gradle (see #1543). That means that the old snipped to add parameters is no longer necessary... we only need the resourcePackageName for flavors with different applicationId than the one in defaultConfig

    android.applicationVariants.all { variant ->
        variant.variantData.variantConfiguration.javaCompileOptions.annotationProcessorOptions.arguments =
                ['androidManifestFile': variant.outputs[0]?.processResources?.manifestFile?.absolutePath,
                 'resourcePackageName': android.defaultConfig.applicationId]
    }
    
    

    the above snipped can me removed instead one can provide the arguments directly from the defaultConfigblock:

    defaultConfig{
        // other config
    
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ['resourcePackageName': android.defaultConfig.applicationId]
            }
        }
    }
    

    with this change the build is working. :)

  11. dodgex commented on Mar 9, 2017

    @dodgex
    Member

    btw and a little bit offtopic:

    you do not need to provide full applicationId for your flavors. The below block has the same effekt than yours. :)

    defaultConfig {
        applicationId "com.github.aleksandermielczarek.androidannotationsannotationprocessorissue"
        
        // other config
    }
    productFlavors {
        dev {
            applicationIdSuffix ".debug"
        }
        prod {
            // uses applicationId from defaultConfig
        }
    }
    
  12. AleksanderMielczarek commented on Mar 9, 2017

    @AleksanderMielczarek
    Author

    @dodgex Thank you for help. I can confirm that it's working now. I remember that arg androidManifestFile was mentioned somewhere in doc and it was part I always paste to every new project.

    And thank you for trick with applicationIdSuffix, really useful👍

  13. dodgex commented on Mar 9, 2017

    @dodgex
    Member

    Nice! I'll close the issue then :)

    Before 4.0.0 androidManifestFile was a required argument and it looks no one updated the wiki :D

  14. dodgex commented on Mar 11, 2017

    @dodgex
    Member
  15. couchcrew-thomas commented on Mar 13, 2017

    @couchcrew-thomas

    It still fails for library projects. I've created a new issue since it does not match the OT of this one. #1974

  16. gustavotaveira commented on Jan 9, 2018

    @gustavotaveira

    Ola amigos eu tive esse mesmo problema. O problema estava no atributo applicationId dentro do build.gradle do projeto android, eu estava usando o id de outro projeto ao inves de usar o id do projeto que eu havia baixado, nisso nem precisei usar esse Jack bugado que criaram.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions