Android库拒绝创建R.java,除非构建为com.Android.application

Android库拒绝创建R.java,除非构建为com.Android.application,android,android-studio,gradle,android-library,aar,Android,Android Studio,Gradle,Android Library,Aar,我有一个gradle项目,正在尝试用资产构建一个Android库,并将其作为AAR文件分发。但是,我只能在使用时获取要生成的R.java文件 apply plugin: 'com.android.application' 然后,它将只生成无法用于分发的APK文件。但是,使用“正确的” 拒绝生成R.java文件,因此我的代码都无法编译 我使用的是AndroidStudio 1.2.1,但它拒绝从命令行或IDE内部构建,因此我认为这与此无关 我尝试过重建、清理、确保我的XML文件不被破坏、删除未使

我有一个gradle项目,正在尝试用资产构建一个Android库,并将其作为AAR文件分发。但是,我只能在使用时获取要生成的R.java文件

apply plugin: 'com.android.application'
然后,它将只生成无法用于分发的APK文件。但是,使用“正确的”

拒绝生成R.java文件,因此我的代码都无法编译

我使用的是AndroidStudio 1.2.1,但它拒绝从命令行或IDE内部构建,因此我认为这与此无关

我尝试过重建、清理、确保我的XML文件不被破坏、删除未使用的res文件夹、不使用自定义属性、尝试过多个版本的build tools/gradle/android api版本以及其他相关问题。我还尝试在应用程序和库之间移动内容,但仍然失败

这是我的项目和库build.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()
    }
}
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'
    }
}
库渐变文件:

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()
    }
}
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'
    }
}

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

有一些相关的QA,你能检查一下它们是否解决了你的问题吗。谢谢你,帕特里克。不幸的是,我确实读过这些书,但似乎没有一本有用。它似乎直接与库和应用程序android插件的使用有关(或者至少与R文件的生成和否有关)。我没有任何损坏的xmls文件或自定义属性、清理和重建等。这些似乎都没有帮助:(在同步gradle文件后,Android Studio的
gradle
选项卡中是否有名为
processResources
的任务?“gradle选项卡”在哪里?当我运行gradlew任务时,我看不到任何以流程开头的任务。我在Android Studio 1.2下有一个库项目构建。库的build.gradle中的buildscript块看起来有点可疑。在我的项目中,所有存储库配置都在project build.gradle中。依赖项下也有一个存储库块。至少有一个f这些都是多余的。不过,我完全不相信这两个都与您的错误有关。您正在运行的命令是什么?它给了您什么错误输出?
/gradlew assembleDebug
为我生成一个app-debug.aar。