Getting problems when trying to setup Jetpack Compose Found interface rPluginContext - android

So, I'm trying to let jetpack compose run with a simple example, I have already updated my kotlin plugin to 1.4.0 and also updated all my build gradle with the jetpack compose documentation, but I got this error when compiling
java.lang.IncompatibleClassChangeError: Found interface
org.jetbrains.kotlin.backend.common.extensions.IrPluginContext, but
class was expected at
androidx.compose.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:41)
I have also downloaded the canary version of Android studio
build.gradle project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.0-rc"
repositories {
google()
jcenter()
maven{
url "https://dl.bintray.com/kotlin/kotlin-eap/"
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven{
url "https://dl.bintray.com/kotlin/kotlin-eap/"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle app
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
defaultConfig {
applicationId "com.jetpackcompose"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
// Enables Jetpack Compose for this module
compose true
}
// Set both the Java and Kotlin compilers to target Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
composeOptions {
kotlinCompilerVersion kotlin_version
kotlinCompilerExtensionVersion "0.1.0-dev13"
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.ui:ui-core:0.1.0-dev13'
implementation 'androidx.ui:ui-tooling:0.1.0-dev13'
implementation 'androidx.ui:ui-layout:0.1.0-dev13'
implementation 'androidx.ui:ui-material:0.1.0-dev13'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
}
}
But I cant compile the app, I'm trying to run the basic example
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent{
sayHello()
}
}
#Preview
#Composable
fun sayHello(){
Text("Hello World")
}
}
Does anyone knows why this error is thrown ?

Using Kotlin version 1.4.10 instead of 1.4.20 solved my problem.

Try to update Compose version to 0.1.0-dev16. Looks like 0.1.0-dev13 isn't compatible with Kotlin 1.4-rc

Related

Failed to resolve in gradle, Unsplash photo picker android studio

I am trying to implement Unsplash API according to this website:
https://unsplash.com/documentation#creating-a-developer-account
But got stuck pretty quickly. I don't know why Gradle refuses to compile so here are some files:
build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
maven { url 'https://jitpack.io' }
}
dependencies {
def nav_version = "2.5.2"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (App)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
id "kotlin-parcelize"
}
android {
compileSdk 33
defaultConfig {
applicationId "com.example.gallery"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'com.example.gallery'
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
// Unsplash
implementation 'com.github.unsplash:unsplash-photopicker-android:1.0.1'
// Kotlin
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
// tests
testImplementation "com.google.truth:truth:1.1.3"
testImplementation "android.arch.core:core-testing:1.1.1"
testImplementation 'org.robolectric:robolectric:4.8'
}
All I try to do is to add those lines (from the GitHub specification):
To integrate UnsplashPhotoPicker into your Android Studio project
using Gradle, specify in your project build.gradle file:
allprojects { repositories {
...
maven { url 'https://jitpack.io' } } } And in your app module build.gradle file, replacing x.y.x by the latest tag:
dependencies { implementation
'com.github.unsplash:unsplash-photopicker-android:x.y.z' }
The problem occured(8 similar problem):
Execution failed for task ':gallery:desugarDebugFileDependencies'.
Could not resolve all files for configuration ':gallery:debugRuntimeClasspath'.
Could not find com.github.unsplash:unsplash-photopicker-android:1.0.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/github/unsplash/unsplash-photopicker-android/1.0.1/unsplash-photopicker-android-1.0.1.pom
- https://repo.maven.apache.org/maven2/com/github/unsplash/unsplash-photopicker-android/1.0.1/unsplash-photopicker-android-1.0.1.pom
Required by:
project :gallery
This question was asked Here but got no answer...
Add the
maven { url 'https://jitpack.io' }
in setting.gradle(project level)
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
//...
maven { url 'https://jitpack.io' }
}
}

How to fix the "Android MPAndroidChart Could not find method dependencyResolutionManagement() for arguments error in gradle"?

well Im trying to use MPAndroidChart library in Android studio
my gradle version was 7.0.2 but it didnt work well.
so i changed gradle Version to 6.7.1, and Android Gradle Plugin Version to 4.2.2
i also changed the version of sdk to Android 11.0(R)
my Target SDK version is 30
--build.gradle(project)
// Top-level build file where you can add configuration options common to all sub-
projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects{
repositories{
google()
mavenCentral()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
--build.gradle(Module)
plugins {
id 'com.android.application'
}
android {
compileSdk 31
BuildToolsVersion '30.0.3'
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories{
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
--setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "My Application"
include ':app'
--capture of the bug
enter image description here
--bug code
Settings file 'C:\Users\kimta\AndroidStudioProjects\MyApplication\settings.gradle' line: 1
A problem occurred evaluating settings 'MyApplication'.
Could not find method dependencyResolutionManagement() for arguments [settings_5pc4jcjs87c9dkfx5manehm0u$_run_closure1#69c68d91] on settings 'MyApplication' of type org.gradle.initialization.DefaultSettings.
gradle problem is too difficult for novice like me. Is there any solution ?
You try to add this line in your settings.gradle:
maven { url 'https://jitpack.io' }
--setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' } //Add this line in your settings.gradle
}
}
rootProject.name = "My Application"
include ':app'
--build.gradle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
--build.gradle(Module)
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.myapplication"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// MPAndroidChart
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}

Why is Kotlin's mutableListOf() returning a null value

I am working through Google's Android developer codelab for the the unscramble app. I am trying to initialize my variable wordsList to be an empty mutable list of strings with:
private var wordsList: MutableList<String> = mutableListOf()
However, during my debugging process, I see that the value of wordsList is null and not an empty list like []. I tested the code in kotlin playground and it should be []. I attached a screenshot of what android studio is showing me. What am I doing wrong, why am I not seeing the expected behavior?
Here is the gradle file for my project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the gradle file for my app
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.android.unscramble"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding = true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
// LiveData
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
// ViewModel
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.fragment:fragment-ktx:1.2.5'
}
Referring to Kotlin docs:
During an instance initialization, the initializer blocks are executed
in the same order as they appear in the class body, interleaved with
the property initializers
So, your breakpoint is probably hit from the upper init { } block when wordsList is not initialized yet. You may choose to initialize your variable before calling getNextWord() or just move this init { } block down so it is executed when all your properties are already initialized.

Gradle AndroidStudio: Plugin [id: 'kotlin-android'] was not found in any of the following sources

Trying to add another android project as module to my project i AndroidStudio
in gradle.settings ad do the following:
include ':appmod'
project(':appmod').projectDir = file('/home/john/AndroidStudioProjects/MyIncludeTest/appmod')
and as dependency in build.gradle I add the following:
implementation project(':appmod')
The gradle couldn't fullfill sync because of the following error
Build file '/home/john/AndroidStudioProjects/MyIncludeTest/appmod/build.gradle' line: 3
Plugin [id: 'kotlin-android'] was not found in any of the following sources:
build.gradle (project) in MyIncludeTest
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (module) in myIncludeTest
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myincludetest"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
What could be the problem, how do I solve it?

Jetpack Compose dev06 setContent() doesn't work?

While updating to dev06 and ran the app I got the following error:
java.lang.NoSuchMethodError: No static method setContent(Landroid/app/Activity;Lkotlin/jvm/functions/Function0;)Landroidx/compose/Composition; in class Landroidx/ui/core/WrapperKt; or its super classes (declaration of 'androidx.ui.core.WrapperKt' appears in /data/app/tt.reducto.composesample-BYNjMDWbVhiprnPCNJw0LA==/base.apk)
If you're coming from dev05, dev04 (or less), there's a migration needed.
UPDATE: This logic works up to Dev09. BETA Release is currently available.
I manage to make it work. You need to do the following:
Android Studio 4.1 Canary 2 or +
gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip
build.gradle: (project level)
buildscript {
ext.kotlin_version = "1.3.70"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0-alpha02"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (app level):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.package.name"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
composeOptions {
kotlinCompilerExtensionVersion = "0.1.0-dev06" // THIS ONE is important
}
buildFeatures {
compose true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
def compose_version = "0.1.0-dev06"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.ui:ui-foundation:$compose_version"
implementation "androidx.ui:ui-framework:$compose_version"
implementation "androidx.ui:ui-tooling:$compose_version"
implementation "androidx.ui:ui-layout:$compose_version"
implementation "androidx.ui:ui-material:$compose_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Once you get all that done, run your code and you'd be good to go.
For Kotlin DSL
kotlinOptions {
jvmTarget = V.JVM.Kotlin.target
useIR = true
}
buildFeatures {
// Enables Jetpack Compose for this module
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.0.0-beta03"
}
Make sure to set compose true inside your gradle file..
for build.gradle.kts
buildFeatures {
compose = true
}
for traditional build.gradle
buildFeatures {
compose true
}
In you apps build.gradle app
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion kotlin_compiler_verion
}
I had the same error with unnecessary dependency in buildSrc/build.gradle.kts
dependencies {
implementation("com.android.tools.build:gradle:7.0.0-beta02")
}
After removing this the error is gone.
compose version 1.0.0-beta07
I got the same error while used Compose dev07. I fixed the issue by giving the below code in build.gradle (app level):
composeOptions {
kotlinCompilerExtensionVersion = "0.1.0-dev07"
}
For more info please check here
For Kotlin DSL(build.gradle.kts):
android {
buildFeatures {
compose = true
composeOptions.kotlinCompilerExtensionVersion = Depends.Versions.composeVersion //"1.0.0-alpha08"
composeOptions.kotlinCompilerVersion = Depends.Versions.kotlinVersion //"1.4.20"
}
gradle-wrapper.properties file ->
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip

Categories

Resources