android-studio - AndroidAnnotations + Android Studio - 找不到生成的 null.R 类

标签 android-studio android-annotations

我已经按照 wiki 说明使用最新版本的 AndroidStudio 设置了 ActiveAndroid。我正在使用产品 flavor 。这是我的 gradle 构建文件:

apply plugin: 'android'
apply plugin: 'android-apt'

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName android.defaultConfig.packageName
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {
        a {
            packageName "com.a.a"
        }

        b {
            packageName "com.a.b"
        }

        c {
            packageName "com.a.c"
        }
    }
}

dependencies {
    apt "org.androidannotations:androidannotations:3.0+"
    compile "org.androidannotations:androidannotations-api:3.0+"
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

Gradle 构建文件,但是当我在设备上编译/去调试时,我收到两个错误:

错误:: 无法找到生成的 null.R 类



错误:任务“:ml:compileADebugJava”的执行失败。

Compilation failed; see the compiler error output for details.



我已经为我的构建文件尝试了很多设置,但我终其一生都无法让它工作。此外,当我尝试从以下位置更改我的 AndroidManifest 时:

android:name="com.a.a.MainActivity"



android:name="com.a.a.MainActivity_"

它指出找不到类。

我正在使用最新版本的 Gradle 和最新版本的 ActiveAndroid。

任何帮助将非常感激。

最佳答案

我知道它晚了,但它可能会帮助某人。

当您修改 applicationId 时会发生这种情况。示例中提供的脚本假定您已声明“android.defaultConfig.applicationId”。在大多数情况下,它为 null,因此它生成 null.R。您可以定义变量或将代码更改为以下内容:

defaultConfig {

    // Rest of Config

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

请注意,原始包名称应与 R 在您的事件中的位置相同。

希望能帮助到你!

关于android-studio - AndroidAnnotations + Android Studio - 找不到生成的 null.R 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22716903/

相关文章:

android - 在 Android Studio 中添加 .so 文件

java - 安卓工作室 : New activity opens as blank screen

android - 在自定义对话框类中使用 Android 注解

android - 使用 AndroidAnnotations 库时何时注入(inject) View ?

android - 找不到库项目 Activity 错误

java - 使用嵌套 TextView 限制 Android Horizo​​ntal ScrollView 的宽度

android - 将 Android Studio 0.6.1 迁移到 0.8 : [PATH] does not appear to be Android Studio config folder or installation home

android - 无法使用 AndroidAnnotations 库在 AndroidStudio 中制作项目

Androidannotations RestErrorHandler 未在 RestClient Robo Spice 请求中调用

java - 对同一按钮使用触摸和单击注释