I hava setted up a App project with retrolambda for JAVA 8 compatibility and a module dependency to a own android library, because I used this part in a second App too. The problem is that every time I build my Project with gradle there is no error and the build success, but when I want to install the App on my Device, gradle fails in
:app:compileDebugJavaWithJavac with package R does not exist
Here is my gradle setup:
build.gradle (Project: "Projectname")
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 (Module: 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'
}
This is the output from gradle console:
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
I'm wondering about this, because my second app with the same setup can be installed without any problem. Why gradle crashs in this app? In my java classes there is while programming no problem and the import to the android R class exists, but while build for installing gradle removed this import and all R's will be red till a few seconds. Android Studio auto import the right R
import my.package.app.R;
and after the import the R's are not red anymore.
I have tested a gradle clean and rebuild several times (as suggested in other questions) without fixing the problem...
Thanks for helping :D