Android Studio:app:compileDebugJavaWithJavac包R不存在

时间:2016-06-21 10:29:06

标签: android android-studio gradle java-8 retrolambda

我hava与retrolambda建立了一个App项目,用于JAVA 8的兼容性和对自己的android库的模块依赖,因为我在第二个应用程序中也使用了这个部分。 问题是每次我使用gradle构建我的项目都没有错误和构建成功,但是当我想在我的设备上安装应用程序时,gradle就失败了

:app:compileDebugJavaWithJavac with package R does not exist

这是我的gradle设置:

build.gradle(项目:“项目名称”)

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'me.tatarka:gradle-retrolambda:3.2.5'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(模块:app)

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "my.package.app"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    packagingOptions {
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:24.0.0'
    compile 'org.florescu.android.rangeseekbar:rangeseekbar-library:0.3.0'
    compile project(path: ':myownmodule')
}

build.gradle(Module:myownmodule)

apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    configurations {
        compile.exclude module: 'support-annotations'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.google.code.gson:gson:2.6.1'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'io.reactivex:rxjava:1.1.3'
}

这是gradle控制台的输出:

Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:compileDebugSources, :app:compileDebugAndroidTestSources, :app:compileDebugUnitTestSources, :myownmodule:generateDebugSources, :myownmodule:mockableAndroidJar, :myownmodule:prepareDebugUnitTestDependencies, :myownmodule:generateDebugAndroidTestSources, :myownmodule:compileDebugSources, :myownmodule:compileDebugUnitTestSources, :myownmodule:compileDebugAndroidTestSources]

Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
Jack is required to support java 8 language features.
Jack is required to support java 8 language features.
:clean
:app:clean
:myownmodule:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:myownmodule:preBuild UP-TO-DATE
:myownmodule:preReleaseBuild UP-TO-DATE
:myownmodule:compileReleaseNdk UP-TO-DATE
:myownmodule:compileLint
:myownmodule:copyReleaseLint UP-TO-DATE
:myownmodule:mergeReleaseProguardFiles UP-TO-DATE
:myownmodule:packageReleaseRenderscript UP-TO-DATE
:myownmodule:checkReleaseManifest
:myownmodule:preDebugAndroidTestBuild UP-TO-DATE
:myownmodule:preDebugBuild UP-TO-DATE
:myownmodule:preDebugUnitTestBuild UP-TO-DATE
:myownmodule:preReleaseUnitTestBuild UP-TO-DATE
:myownmodule:prepareComAndroidSupportAnimatedVectorDrawable2400Library
:myownmodule:prepareComAndroidSupportAppcompatV72400Library
:myownmodule:prepareComAndroidSupportSupportV42400Library
:myownmodule:prepareComAndroidSupportSupportVectorDrawable2400Library
:myownmodule:prepareIoReactivexRxandroid110Library
:myownmodule:prepareReleaseDependencies
:myownmodule:compileReleaseRenderscript
:myownmodule:generateReleaseResValues UP-TO-DATE
:myownmodule:generateReleaseResources
:myownmodule:packageReleaseResources
:myownmodule:compileReleaseAidl
:myownmodule:generateReleaseBuildConfig
:myownmodule:mergeReleaseShaders
:myownmodule:compileReleaseShaders
:myownmodule:generateReleaseAssets
:myownmodule:mergeReleaseAssets
:myownmodule:mergeReleaseResources
:myownmodule:processReleaseManifest
:myownmodule:processReleaseResources
:myownmodule:generateReleaseSources
:myownmodule:incrementalReleaseJavaCompilationSafeguard
:myownmodule:compileReleaseJavaWithJavac
:myownmodule:compileRetrolambdaRelease
:myownmodule:processReleaseJavaRes UP-TO-DATE
:myownmodule:transformResourcesWithMergeJavaResForRelease
:myownmodule:transformClassesAndResourcesWithSyncLibJarsForRelease
:myownmodule:mergeReleaseJniLibFolders
:myownmodule:transformNative_libsWithMergeJniLibsForRelease
:myownmodule:transformNative_libsWithSyncJniLibsForRelease
:myownmodule:bundleRelease
:app:prepareProjectnameBalldbmodelUnspecifiedLibrary
:app:prepareComAndroidSupportAnimatedVectorDrawable2400Library
:app:prepareComAndroidSupportAppcompatV72400Library
:app:prepareComAndroidSupportDesign2400Library
:app:prepareComAndroidSupportRecyclerviewV72400Library
:app:prepareComAndroidSupportSupportV42400Library
:app:prepareComAndroidSupportSupportVectorDrawable2400Library
:app:prepareIoReactivexRxandroid110Library
:app:prepareOrgFlorescuAndroidRangeseekbarRangeseekbarLibrary030Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:mergeDebugAndroidTestShaders
:app:compileDebugAndroidTestShaders
:app:generateDebugAndroidTestAssets
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:mockableAndroidJar
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/HersListAdapter.java:37: error: package R does not exist
        View layout = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_hers, parent, false);
                                                                        ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/HersListAdapter.java:56: error: package R does not exist
                ListActivity.switchTo(listActivity, str(R.string.series)+" " + hers.getName(), hers);
                                                                             ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/HersListAdapter.java:80: error: package R does not exist
            root = (LinearLayout) layout.findViewById(R.id.root);
                                                       ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/HersListAdapter.java:82: error: package R does not exist
            hersImg = (ImageView) layout.findViewById(R.id.hersImg);
                                                             ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/HersListAdapter.java:84: error: package R does not exist
            hersname = (TextView) layout.findViewById(R.id.hersname);
                                                             ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/HersListAdapter.java:85: error: package R does not exist
            ballanzahl = (TextView) layout.findViewById(R.id.count);
                                                         ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/PassListAdapter.java:35: error: package R does not exist
        View layout = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_two_lines, parent, false);
                                                                        ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/PassListAdapter.java:61: error: package R does not exist
            root = (LinearLayout) layout.findViewById(R.id.root);
                                                       ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/PassListAdapter.java:63: error: package R does not exist
            line1 = (TextView) layout.findViewById(R.id.line1);
                                                    ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/PassListAdapter.java:64: error: package R does not exist
            line2 = (TextView) layout.findViewById(R.id.line2);
                                                    ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/PisteListAdapter.java:35: error: package R does not exist
        View layout = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_two_lines, parent, false);
                                                                        ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/PisteListAdapter.java:65: error: package R does not exist
            root = (LinearLayout) layout.findViewById(R.id.root);
                                                       ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/PisteListAdapter.java:67: error: package R does not exist
            line1 = (TextView) layout.findViewById(R.id.line1);
                                                    ^
/path/to/project/Projectname/app/src/main/java/my/package/app/adapter/PisteListAdapter.java:68: error: package R does not exist
            line2 = (TextView) layout.findViewById(R.id.line2);
                                                    ^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
14 errors

 FAILED
:app:compileRetrolambdaDebug FAILED

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:compileRetrolambdaDebug'.
> Process 'command '/path/to/jdk_1.8.0-72_x86_64/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
==============================================================================

BUILD FAILED

Total time: 32.407 secs

我对此感到疑惑,因为我的第二个具有相同设置的应用程序可以毫无问题地安装。 为什么要在这个应用程序中发生崩溃?在我的java类中,编程没有问题,并且存在对android R类的导入,但是当安装gradle的构建移除了这个导入并且所有R将是红色直到几秒钟。 Android Studio自动导入右R

import my.package.app.R;

导入后,R不再是红色。

我已经测试过gradle clean并重建了几次(如其他问题所示)而没有解决问题......

感谢您的帮助:D

1 个答案:

答案 0 :(得分:0)

我最近有一个项目工作正常,直到今天发生同样的错误。

错误:任务':app:mergeDebugResources>执行失败1

我尝试了所有常用的修复程序,重新启动,重新同步,清理解决方案,使缓存无效并重新启动。直到......才有效:

修复:

对于每个类中的每个build.gradle文件,您将看起来像这样:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.ac130.memorygame"
        minSdkVersion 21
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
}

现在,打开一个新项目。这个新项目应该调试得很好。从Gradle Scripts复制并粘贴新项目build.gradle,并用该代码替换旧/已损坏项目的build.grade文件。将应用程序ID更改为旧项目中的内容。使用Gradle保存并重新同步。您现在可以使用您的应用程序!。