Android注解和applicationIdSuffix

标签 android android-gradle-plugin android-annotations

我一直在尝试 Android annotations最近一切都运行良好,直到我决定在我的 build.gradle 文件中的 buildTypes 中添加 applicationIdSuffix 。目前它看起来像这样:

buildTypes {
    debug {
        applicationIdSuffix '.debug'
    }

    ...
}

编译后,我在 gradle 控制台中得到以下日志:

:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:pre_testBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
No matching client found for package name 'org.me.myapp.debug'
:app:generateDebugResources
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac
Note: Resolve log file to /dir/myapp/app/build/generated/source/apt/androidannotations.log
Note: Initialize AndroidAnnotations 3.3.1 with options {androidManifestFile=/dir/myapp/app/build/intermediates/manifests/full/debug/AndroidManifest.xml}
Note: Start processing for 4 annotations on 18 elements
Note: AndroidManifest.xml file found with specified path: /dir/myapp/app/build/intermediates/manifests/full/debug/AndroidManifest.xml Note: AndroidManifest.xml found: AndroidManifest [applicationPackage=org.me.myapp.debug, componentQualifiedNames=[org.me.myapp.ui.MainActivity_, net.hockeyapp.android.UpdateActivity], permissionQualifiedNames=[android.permission.ACCESS_WIFI_STATE, android.permission.ACCESS_NETWORK_STATE], applicationClassName=null, libraryProject=false, debugabble=false, minSdkVersion=15, maxSdkVersion=-1, targetSdkVersion=22]
error: The generated org.me.myapp.debug.R class cannot be found
Note: Found Android class: android.R
Note: Time measurements: [Whole Processing = 15 ms], [Extract Manifest = 4 ms], [Extract Annotations = 3 ms],
Note: Finish processing
Note: Start processing for 0 annotations on 0 elements
Note: Time measurements: [Whole Processing = 0 ms],
Note: Finish processing
1 error
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.

我尝试再次清理和重建,从项目中删除 generated 目录,但没有任何帮助。如果我从 build.gradle 文件中删除 applicationIdsuffix,一切正常。我该如何解决这个问题?

最佳答案

对我来说,这是因为 google-services.json 指的是我的生产包名称。在撰写本文时最好的解决方案似乎是编写自己的 gradle 任务以在文件的 releasedebug 版本之间切换,或者包括两个包名称在文件中:

google-services.json for different productFlavors

关于Android注解和applicationIdSuffix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31116644/

相关文章:

android - 突然我在 Eclipse 中遇到了太多错误

android - 可以在 Android Studio 的 drawable 文件夹中创建子文件夹吗?

android - 使用 Android Annotation REST 服务的 POST 请求

java - 如何访问android注解sharedPreference?

android - 当多个标记显示在 android map 上时 Progressdialog 卡住

android - 如何发送 HTML 电子邮件

java - runOnUiThread 不起作用

android - Gradle BuildConfigFields 语法

android - Gradle 3.0.0 的 Proguard 问题

Android-注解与继承