When I enable the Jack compiler in Android Studio 2.2 the Dagger 2 component is not generated. Can Dagger 2 be used with Jack? If so, how would I go about configuring my application?
From my application's build.gradle:
jackOptions {
enabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
I sunk like 2 days into figuring this out. So I'm circling back to posting the findings here in case it saves someone time:
This is caused by a bug in Jack that prevents classpaths from working properly. It has to do with Jack running "in-process" (in the same JVM as the gradle daemon). Setting android.defaultConfig.jackOptions.jackInProcess to false does get beyond the "Preconditions" error but it causes other problems (2 JVMs that hog system resources) & bugs that break the build in other (worse) ways.
For now, the best solution seems to be:
Wait for the 2.3 release of the Android gradle plugin, which already has the fix for this.
Downgrade Dagger to v2.2, in the meantime.
It's the highest version that seems to avoid the Guava conflict with Jack.
EDIT: update 1/14/2017:
I ran into several OTHER problems with Jack and got so tired of it that I switched to retrolambda and kicked myself for not doing this earlier! Right now, Jack simply seems to cause more problems than it solves. Just add the lines with a plus and delete the lines with a minus and you can return to Dagger 2.8 while waiting for Jack to get it's act together!
+plugins {
+ id "me.tatarka.retrolambda" version "3.4.0"
+}
apply plugin: 'com.android.application'
+apply plugin: 'me.tatarka.retrolambda'
- jackOptions {
- enabled true
- }
For even faster retrolambda builds, add org.gradle.jvmargs=-Xmx4608M to your gradle.properties file so that dexing can happen in-process. Now, I'm on Dagger 2.8 and my clean builds are only 12 seconds, GOOD RIDDANCE, JACK!
The documentation page on Jack and Jill has instructions specific to annotation processors "to be applied at compile time but not to be included in your APK", advising the use of the annotationProcessor dependency scope. The example coincidentally mentions Dagger 2:
dependencies {
compile 'com.google.dagger:dagger:2.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}
Jack is now deprecated, see this post.
You have to upgrade your Android Studio to 3.0 preview 1, to be able to use Java 8.
If you can't upgrade it (conflict with other lib), or you want to wait for a release version, you can try this workaround solution :
Add the retrolamba lib, follow instructions here.
Related
All I wanted to do in my Android Native app using Jetpack Compose was to use some of the newer versions of some of the software. I guess I should have known better, because this has turned into the usual dependency nightmare. I have wasted all afternoon trying to get this to compile and run.
I’ll start with the error message, and work backwards:
> Task :app:compileDebugKotlin FAILED
> 'compileDebugJavaWithJavac' task (current target is 17) and 'compileDebugKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
> e: This version (1.2.0-alpha05) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.10 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
First, I have no idea why the compileDebugKotlin thinks I am targeting JVM 1.8 instead of 17. My JAVA_HOME is set to Java 17, my IntelliJ Project Structure JDK is set to 17, and my app:build.gradle has the following:
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
I do not see 1.8 being set anywhere.
The next issue is the Compose Compiler version that the error message is showing, 1.2.0-alpha05. I am setting the following in my root build.gradle file:
buildscript {
ext {
compose_version = '1.3.0'
…
And then referring to it in my app:build.gradle file:
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
I have no idea where it’s coming up with 1.2.0-alpha05 as the version.
The next issue is that it thinks I'm using Kotlin 1.7.10. I have set the Kotlin version to 1.6.10 in the IntelliJ preferences for Kotlin compiler, as well as 17 for the JVM. I tried the following in build.gradle, but it seems to be ignored, it is making no difference:
kotlin {
version("1.6.10")
}
In a nutshell, I have no idea where any of these version numbers are coming from, and how to set them so that they reflect the reality that I thought I was configuring correctly. I have cleared the IntelliJ cache and restarted numerous times.
the two task shown in the error have different functions during a build
compileDebugJavaWithJavac is responsible for generating the bytecode for the Java Code and making it available for further processing. which in your case is targeted to java 17 but compileDebugKotlin is responsible for making bytecode for kotlin code in your case it is targeted to 1.8 ,that is not supported so you should add
kotlinOptions {
jvmTarget = '17'
}
composeCompiler is not Compatible with all versions of Kotlin. Each compose compiler has corresponding compatible Kotlin Version (Compose to Kotlin Compatibility Map). what you shown is compose_version which do not represent Compose Compiler, they are declared in
composeOptions {
kotlinCompilerExtensionVersion = "1.x.x"
}
To support Instant Run in my version of Android Studio, I needed to upgrade my Gradle plugin from version 2.2.3 to 2.3.3
I'm aware I'm supposed to migrate to annoationProcessor and I believe I've followed that guide correctly
after doing so, the Android DataBinding code generation fails
The migration guide linked earlier states that all I need is to
Make sure you are on the Android Gradle 2.2 plugin or newer
Remove the android-apt plugin from your build scripts
Change all apt, androidTestApt and testApt dependencies to their new format
This should be all that's needed to successfully build the project. Yet it doesn't build.
Build output
Gradle build finished with 101 error(s) and 23 warning(s) in 12s 481ms
All of the errors follow the same pattern:
C:\Users...\FooAdapter.java
error: package com.example.app.databinding does not exist
error: cannot find symbol class ItemFooBinding
An interesting message can be found in the build console:
Warning:The following options were not recognized by any processor: '[android.databinding.minApi, android.databinding.enableDebugLogs, android.databinding.sdkDir, android.databinding.bindingBuildFolder, android.databinding.enableForTests, android.databinding.modulePackage, android.databinding.generationalFileOutDir, android.databinding.xmlOutDir, android.databinding.artifactType, android.databinding.printEncodedErrors, android.databinding.isTestVariant]'
I would like to point out that...
I presume I don't have an error in some XML file, binding expression or a naming issue. The same set of sources and XML build when I switch back to the Git branch with the old gradle plugin version (and all of the other source files up-to-date)
I did increase the limit of output build errors as discussed here, although this doesn't seem to be relevant right now, since as you can see, I currently have "only" 101 errors. :)
Additional info
The following diffs show how I've modified my gradle files:
build.gradle DiffChecker link
app/build.gradle DiffChecker link
Also, as a quick overview, here is the list of some of the "more interesting" plugins & libraries used by the project:
Kotlin
Android DataBinding
Realm
Retrofit
Dagger
ButterKnife (I know...)
Multidex Support Library
Does anyone have a clue what could be the issue? Any help or idea will be greatly apprecitated!
I had exactly the same warning. This line in gradle solved the issue:
kapt "com.android.databinding:compiler:3.0.1"
Hopefully, it will help somebody
Update:
3.0.1 is Android Plugin Version.
When you see innumerable build errors mentioning databinding as in this case, the problem usually lies somewhere else. Databinding just gets stopped in its tracks by unrelated build problems and complains exceedingly loudly. The only way to deal with it is to locate the build errors that are not tied to databinding. Once they are fixed, databinding can do its thing again and be silent. Unfortunately you often have to repeat this approach several times until you have found all non-databinding issues. It's an arduous task for sure, but unfortunately there is nothing else you can do until Google manages to provide a saner build environment.
This is the reason why you are advised to increase the build error limit beyond 100 - you would not see the actual errors causing your problems, because they commonly do not show up early in the list.
I will chance a guess - Dagger 2 is a common source of triggering this problem, which could be related to your annotationProcessor change; so look out for Dagger errors. But your issues could be caused by other things, like other annotation processors as you mentioned - you wouldn't know for sure until you diligently dig through your build errors.
It seems it all comes down to my project using Kotlin. Actually we have it mixed: some classes use plain old Java while others are written in Kotlin. An incomplete migration. :)
I assume that without Kotlin, replacing apt with annotationProcessor would be enough and I wouldn't have ran into this issue at all.
Solution
Annotations need to be processed by both annotationProcessor and kapt, which seems to be Kotlin's own annotation processor.
For each Gradle dependency that uses annotations, you should have both of the following in your app-level build.gradle:
annotationProcessor 'com.example.my.library:x.y.z
kapt 'com.example.my.library:x.y.z
I using lombok on some project, and with the new Android Studio 2.4 Update now (Preview) I get this strange error:
What went wrong: Execution failed for task
':core:javaPreCompileRelease'. Annotation processors must be
explicitly declared now. The following dependencies on the compile
classpath are found to contain annotation processor. Please add them
to the annotationProcessor configuration.
- lombok-1.16.16.jar Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath
= true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See
https://developer.android.com/r/tools/annotation-processor-error-message.html
for more details.
I already tried:
annotationProcessor "org.projectlombok:lombok:1.16.16"
but has no effect.
I also tested:
android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath
= true
But also has no effect.
Also checked the support page for further information but with no luck, anyone of you possibly?
https://developer.android.com/studio/preview/features/index.html?utm_source=android-studio#annotationProcessor_config
Update:
provided "org.projectlombok:lombok:1.16.16" // keep
annotationProcessor "org.projectlombok:lombok:1.16.16" // add this
Just worked perfectly, but I have two Android Studio modules, and two build.gradle files.
The error log just changed a bit (module prefix), and I thought the fix didn't work.
But after applying the fix to both build.gradle files everything worked perfectly.
I had the same problem but needed a slightly different fix (although the idea came from the accepted answer above - https://stackoverflow.com/a/43820494/1777346)
Turned out I already had the provided and annotationProcessor in both build.gradle files.. but, I also had a compile entry. Removing it fixed this issue for me:
compile 'org.projectlombok:lombok:1.16.16' // remove this
provided 'org.projectlombok:lombok:1.16.16'
annotationProcessor "org.projectlombok:lombok:1.16.16"
Just figured I'd add my findings in case it helps anyone. I'm using Android Studio 3.0 Canary 4 and gradle:3.0.0-alpha4 in my unending quest to get build times down.. which never seems to pay off :)
I recently discovered the property testOptions.animationsDisabled in the Android Gradle plugin.
I was hoping it would be helpful to disable the animations on my devices when executing UI tests with Espresso, but it's not, i.e. I still have to disable the animations manually or using one of several options available. Otherwise some UI tests become flaky.
Since the description of this property is rather short, does anyone know how it's meant to be used?
My gradle file is as follows:
apply plugin: 'com.android.application'
android {
testOptions {
animationsDisabled = true
}
}
Thanks.
Unfortunately, nothing.
I added a comment a while ago that it is not used in the 2.3.3 plugin.
I hoped something changed with the Android Studio 3.1 and androidGradle 3.1 plugin release but that isn't the case.
I think it is a bit misleading that this flag exists and isn't better documented
Edit:
I have been forwarded this blog post that explains how to set up a test rule that disables animations for you.
https://proandroiddev.com/one-rule-to-disable-them-all-d387da440318
You should be upgrade build:gradle:2.3.0'
and build
simple:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
Since android gradle plugin has enabled incremental build by default annotation processing breaks, because only those classes who has been changed since last incremental build will be taken into account from annotation processors.
So for java source code we usually use apt grald plugin to run annotation processing. However, android's gradle plugin automatically disables gradle's incremental build feature if apt is used in the same project:
https://github.com/google/dagger/issues/298
Now I'm working on a kotlin project and Im facing the same incremental build issue with kapt. So the solution, as with apt, is to disable incremental build. The documentation says:
android {
compileOptions.incremental = false
...
}
However, that doesn't work for me. Does anybody know how to disable incremental builds?
You can add
kotlin.incremental=false
to your gradle.properties file to disable the incremental building.
I had the same issue but it seems to be fixed in version 1.0.4. Currently, it's still in the EAP phase so you'll have to add another repository.
repositories {
...
maven { url 'http://dl.bintray.com/kotlin/kotlin-dev' }
}
Then change the version to 1.0.4-eap-xx in your root build.gradle
buildscript {
ext.kotlin_version = '1.0.4-eap-84'
...
}
Here's the link to the issue.