除了构建为com.android.application之外,Android库拒绝创建R.java

时间:2015-05-08 01:53:41

标签: android android-studio gradle android-library aar

我有一个gradle项目,我正在尝试使用资源构建一个Android库并将其作为AAR文件进行分发。但是,我只能在使用

时生成R.java文件
apply plugin: 'com.android.application'

然后它只会生成无法分发的APK文件。但是,使用"正确"

apply plugin: 'com.android.library'

拒绝生成R.java文件,因此我的代码都没有编译。

我正在使用Android Studio 1.2.1,但它拒绝从命令行或IDE中构建,因此我认为这是无关紧要的。

我尝试过重建,清理,确保我的XML文件没有损坏,删除未使用的res文件夹,我没有使用自定义的attrs,尝试了多个版本的build tools / gradle / android api版本,就像其他相关问题一样。我也试过在应用程序和库之间移动东西,但它仍然失败。

这是我的项目AND库build.gradle文件

项目gradle文件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
        classpath 'com.github.dcendents:android-maven-plugin:1.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

库gradle文件:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

//apply plugin: 'com.android.application'
apply plugin: 'com.android.library'
apply plugin: 'maven'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }
    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            shrinkResources false
            buildConfigField "String", "URL_BASE", "\"http://10.0.3.2:3000\""
        }
        staging {
            debuggable false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "URL_BASE", "\"http://10.0.3.2:3000\""
        }
        release {
            debuggable false
            minifyEnabled true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "URL_BASE", "\"http://10.0.3.2:3000\""
        }
    }
    packagingOptions {
        exclude 'LICENSE.txt'
    }
}

dependencies {
    repositories {
        mavenCentral()
    }

    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.+'
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.jakewharton:butterknife:5.1.2'
    compile 'io.reactivex:rxjava:1.0.8'
    compile 'io.reactivex:rxandroid:0.24.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'joda-time:joda-time:2.7'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
    compile 'com.squareup.okhttp:okhttp:2.3.0'

    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:22.1.1'
    }

    // Espresso
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.0')
    androidTestCompile('com.android.support.test:testing-support-lib:+')

    // Robolectric
    testCompile 'junit:junit:4.12'
    testCompile 'org.hamcrest:hamcrest-core:1.1'
    testCompile 'org.hamcrest:hamcrest-library:1.1'
    testCompile 'org.hamcrest:hamcrest-integration:1.1'

    // TODO: requires special build of robolectric right now. working on this...
    testCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }
}

1 个答案:

答案 0 :(得分:0)

我终于意识到主项目的R.java文件实际上包含了正确的id,但是我收到了一个令人困惑的错误消息,让我相信在Butterknife注释中没有正确的非最终值。不幸的是Gradle没有给我一个我能理解的错误