Yesterday I updated Android Studio Version and Kotlin plugin version.
Android Studio Version: 3.1.2
Kotlin Version: 1.2.41
When I create an Android project using this configuration, I get Kotlin Compiler warning saying
w: /home/ganeshtikone/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre7/1.2.41/9e7a6f582de73d9cdc6c56ef4e23604a0ee55768/kotlin-stdlib-jre7-1.2.41.jar: kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead
Changed as per suggestion, then I am getting following error
Unexpected inputs: ImmutableJarInput{name=org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.41, file=/home/ganeshtikone/Workspace/May-2018/fhs/app/build/intermediates/transforms/desugar/stage/debug/45.jar, contentTypes=CLASSES, scopes=EXTERNAL_LIBRARIES, status=REMOVED}
Go to Tools > Kotlin > Configure Kotlin Plugin Updates and check for updates
then in your app gradle file replace jre with jdk
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Update
Newer version is jdk8
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
Important Update
Must check JDK version before setting config
Kotlin gradle config page has detailed information about this.
First of all check your kotlin version in gradle file.
if (kotlin_version == '1.2.x' ) (Use jdk NOT jre)
First check your jdk version in File > Project Structure.
Or check in build.gradle
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
if (jdk_version == 1.8)
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
if (jdk_version == 1.7)
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
if (jdk_version is < 1.7)
implementation"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
else if(NO jdk version is set in Project Structure)
if(Android_Studio_Version < 2.2.1){
your_jdk_version = 1.7;
}
else {
your_jdk_version = 1.8;
}
Because Android Studio is bundled with jdk 1.8 since 2.2.1 version.
2. else if ( kotlin_version == '1.1.x') (Use jre NOT jdk)
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" // or jre8
Update Kotlin Version?
You can update Kotlin version from Tools > Kotlin > Configure Kotlin Updates
Something is transitively importing those libraries. Run Gradle task dependencies to figure out what.
In my case, it was io.vertx:vertx-lang-kotlin-coroutines:3.5.1.
If there is no update for the dependency, there is not much you can do about it
After reading Kotlin Gradle Script Topic
I find out that some ponits
If you're targeting JDK 7 or JDK 8, you can use extended versions of the Kotlin standard library which contain additional extension functions for APIs added in new JDK versions. Instead of kotlin-stdlib, use one of the following dependencies:
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
I used implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" in my project. I think it's because of compileOptions set in build.graddle
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
You must swap the codes below:
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
Not jre > jdk
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Change SDK7 to Java SDK8
try this:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
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"
}
I am getting this error in view bindings file generated by Android studio. I have added
buildFeatures {
viewBinding true
}
to the app build.gradle file.
In your build.gradle(:app) file,
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Try changing the java version.
I got the same error when using VERSION_11 but the VERSION_1_8 fixed the issue.
Android Studio don' t update Gradle to version 7.
Open project Structure, you can find in File, set in Project:
Android Gradle Plugin Version: 7.0.0
and
Gradle Version: 7.0.2
Compile now and all will work fine.
Updating the android studio to the latest version fixed the issue for me.
I upgraded my android studio to 3.4 canary and now I cannot successfully build anymore due to the following error:
The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.
More details:
Caused by: java.lang.RuntimeException: Failed to transform '.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/9.0.0-SNAPSHOT/732f93940c74cf32a7c5ddcc5ef66e53be052352/butterknife-compiler-9.0.0-SNAPSHOT.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.)
Clearly, its something to do with Butterknife, androidx and Jetifier
Do anybody know how to fix this?
New correct answer:
Butterknife 10.0.0 added support for AndroidX.
dependencies {
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}
Old answer for Butterknife < 10.0.0:
Try blacklisting butterknife from the jetifier:
gradle.properties file:
android.jetifier.blacklist = butterknife.*\\.jar
You need to be on the 3.3.0-rc1 of the AGP and the 1.3.0 version of the Kotlin Gradle plugin:
buildscript {
repositories {
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-rc01'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0"
classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-rc2'
}
}
Add the last version of the butterknive dependency you can check it here if it changes (https://github.com/JakeWharton/butterknife).
It supports androidX. Then go to your app build graddle and replace the old version with the following:
dependencies {
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}
For androidx simply upgrade your dependencies to version '10.0.0'
dependencies {
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}
Look for documentation here
Upgrade ButterKnife to latest version and make sure to add these into your build.gradle(app):
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
My project doesn't use butterknife, but I had the same error "The given artifact contains a string literal with a package reference 'android.support.v4.widget' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx
"
This what I did to solve it: Update your parceler version
gradle build file
Replace:
annotationProcessor 'org.parceler:parceler:1.1.6'
implementation 'org.parceler:parceler-api:1.1.6'
With:
annotationProcessor 'org.parceler:parceler:1.1.13'
implementation 'org.parceler:parceler-api:1.1.13'
Which version if Butterknife you use? Latest version 9.0.0-rc2 supports androidx.
UPD: There is closed issue on butterknife's github repo. Temporary workaround
Add android.jetifier.blacklist=butterknife-compiler to your gradle.properties file.
Using the latest version of Butterknife resolved the issue. Use >= 9.0.0-rc2 (Butterknife Version) to support androidX.
For the latest release check the link - https://github.com/JakeWharton/butterknife/releases
Change
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
or other Material Themes.
Got this error after starting New Project with "No Activity" in Android Studio 4.0.1
update butterknife + invalidate cache and restart + sync gradle
if buterknife not used just clear cache and restart
As per mentioned in developer.android website
"The Jack toolchain is deprecated, as per this announcement. If your
project depends on Jack, you should migrate to using Java 8 support
built into Android Studio’s default toolchain."
I need to use lambda expressions so I have disabled the jack options, but when I compile my code, I get the following error
Error:Jack is required to support Java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.
Below is the screenshot of my build.gradle file
Check you version of com.android.tools.build:gradle.
I had the same error. My solution:
set com.android.tools.build:gradle:3.0.0-alpha6
update kotlin to 1.1.3-2
add to repositories google()
I'm using AS 3.0 Canary 6.
You should do the following:
Update your Android Studio to version 3.0.1.
Upgrade your gradle to 'com.android.tools.build:gradle:3.0.1'
Make sure you buildToolsVersion is at least 26.0.2.
After that you can remove Jack options and use supported Java 8 features.
I moved my android app over to Android Studio without switching to Gradle. Now I want to move to Gradle. The app compiles in Android Studio before switching to Gradle, but now that I have Gradle all set up, it won't compile the String Switch Statements or the diamond operators. The error I am getting is
Gradle: error: strings in switch are not supported in -source 1.6
(use -source 7 or higher to enable strings in switch)
I have made sure that I am running on JRE 7 by printing the
System.getProperty("java.version")
in a task. The output is
1.7.0_25
What confuses me most is the discrepancy between "-source 1.6" and "use -source 7". But I know that both of these are names for Java sdk's so maybe the titles are just being mixed up.
Is there a Gradle setting I need to set? or is this not possible in Gradle? If not it is confusing why it works without Gradle.
It should be noted that the without Gradle version of my project runs the default Android Studio build. I didn't write an ant script or maven script for building it. One of those may be the way it is being built, but I don't have any project specific files for them. Just the Android Studio .iml files.
UPDATE
I tried adding the following to the build.gradle android{} section
compileOptions {
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_7
targetCompatibility = org.gradle.api.JavaVersion.VERSION_1_7
}
but the .class files failed to build and it weren't included in the apk. See the "Android Projects Need Libraries Compiled with Java 1.6" section on this post
You can upgrade an existing Android app/library module to Java 7 by adding the following in the android section of your build.gradle:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
For a Java (non-android) module, you should add the following to build.gradle just after apply plugin: 'java':
sourceCompatibility = 1.7
targetCompatibility = 1.7
For both types of modules, you will need to manually change the language level of your project in File -> Project Structure -> Project (or you can manually edit the config in .idea/misc.xml from JDK_1_6 to JDK_1_7).
You might also need to add the following to .idea/compiler.xml, in the <component name="CompilerConfiguration"> block (but see how you get on without it first):
<bytecodeTargetLevel target="1.7" />