当前位置:  开发笔记 > 编程语言 > 正文

AndroidAnnotations + Android Studio - The generated null.R class cannot be found

如何解决《AndroidAnnotations+AndroidStudio-Thegeneratednull.Rclasscannotbefound》经验,为你挑选了1个好方法。

I have setup ActiveAndroid as per the wiki instructions using latest version of AndroidStudio. I am using product Flavours. This is my gradle build file:

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 build files but when I compile/go to debug on the device I receive two errors:

Error:: The generated null.R class cannot be found

and

Error:Execution failed for task ':ml:compileADebugJava'.

Compilation failed; see the compiler error output for details.

I have tried numerous setups for my build file but cannot for the life of me get it work. Also when I try and change my AndroidManifest from:

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

to

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

it states that class cannot be found.

I am using latest version of Gradle and latest version of ActiveAndroid.

Any help would be much appreciated.



1> Vivek Soneja..:

我知道已经晚了,但是可能会帮助别人。

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

defaultConfig {

    // Rest of Config

    javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["resourcePackageName": ""]
            }
    }
}

请注意,原始包名称应与活动中R的位置相同。

希望能帮助到你!

推荐阅读
虎仔球妈_459
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有