Categories
discuss

Could not find androidx.compose:compose-compiler:1.0.0-beta03

I have tried looking for solution to this in other places, including from a couple questions on stack overflow, but they don’t provide solution to my problem. So please don’t mark my question as duplicate.

I am trying to use Jetpack Compose with Android Studio Canary. I tried setting up the project according to the documentation, but I’m getting the following error on running the project:

Execution failed for task ':app:prepareDebugKotlinCompileTask'.
> Could not resolve all files for configuration ':app:kotlin-extension'.
   > Could not find androidx.compose:compose-compiler:1.0.0-beta03.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/androidx/compose/compose-compiler/1.0.0-beta03/compose-compiler-1.0.0-beta03.pom
       - https://jcenter.bintray.com/androidx/compose/compose-compiler/1.0.0-beta03/compose-compiler-1.0.0-beta03.pom
       - https://jitpack.io/androidx/compose/compose-compiler/1.0.0-beta03/compose-compiler-1.0.0-beta03.pom
       - http://dl.bintray.com/glomadrian/maven/androidx/compose/compose-compiler/1.0.0-beta03/compose-compiler-1.0.0-beta03.pom
       - https://repo.maven.apache.org/maven2/androidx/compose/compose-compiler/1.0.0-beta03/compose-compiler-1.0.0-beta03.pom
     Required by:
         project :app

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

Here is my app level build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 30

    defaultConfig {
        applicationId "com.example.voodlee0125"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "0.1.25"
        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        viewBinding = true
        compose true
    }

    composeOptions {
        kotlinCompilerVersion "1.4.31"
        kotlinCompilerExtensionVersion '1.0.0-beta03'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
        useIR = true

    }

    buildTypes {
        debug {
            minifyEnabled false
            debuggable true
//            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled false
            debuggable true
//            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    def lifecycle_version = "2.3.1"

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation "androidx.drawerlayout:drawerlayout:1.1.1"
    implementation "androidx.navigation:navigation-fragment:2.3.3"
    implementation "androidx.navigation:navigation-ui:2.3.3"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'com.shawnlin:number-picker:2.4.11'
    implementation 'com.karumi:dexter:6.2.1'
    implementation 'com.github.IslamKhSh:CardSlider:1.0.1'
    implementation 'com.intuit.sdp:sdp-android:1.0.6'
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    implementation 'com.google.android.gms:play-services-auth:19.0.0'
    implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.0'
    implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:3.0.0-RC2'
    // Lottie dependency
    implementation "com.airbnb.android:lottie:3.4.0"

    //Autostart settings open
    implementation 'com.thelittlefireman:AppKillerManager:2.1.1'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    // JSON Parsing
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'

    implementation 'com.android.support:multidex:1.0.3'

    implementation 'androidx.cardview:cardview:1.0.0'

    // ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"

    implementation "androidx.core:core-ktx:1.3.2"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.30"

    implementation "org.koin:koin-core:2.2.2"
    implementation "org.koin:koin-androidx-viewmodel:2.2.2"
    implementation "androidx.datastore:datastore-preferences:1.0.0-alpha08"
    implementation 'com.github.pwittchen:swipe-rx2:0.3.0'
    implementation "androidx.compose.material:material:1.0.0-beta03"
    implementation "androidx.compose.ui:ui-tooling:1.0.0-beta03"
    implementation "androidx.compose.runtime:runtime:1.0.0-beta03"
    implementation "androidx.compose.compiler:compiler:1.0.0-beta03"
    implementation "androidx.ui:ui-framework:0.1.0-dev03"



    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'


}
repositories {
    mavenCentral()
}

This is my project level build.gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.4.30'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        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://jitpack.io"
        }

        maven {
            url "http://dl.bintray.com/glomadrian/maven"
        }

    }


}

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

Please suggest a solution.

Answer

Don’t know why and I have not found any meaningful explanation for it since Jetpack Compose Documentation does not tell any restriction about gradle version but I think it requires gradle version 4.2 and above. com.android.tools.build:gradle:4.2.0-alpha16. With this version I was able to use the jetpack compose.

Categories
discuss

Test Error – NoClassDefFoundError: Failed resolution of: Lorg/hamcrest/Matchers

I am using Espresso for Instrumented Test but got this error on the Stack Trace:

enter image description here

The error being caused by a missing class as shown below:

Caused by: java.lang.ClassNotFoundException: Didn't find class "org.hamcrest.Matchers" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/android.test.base.jar", zip file "/data/app/~~vnZzxGNKnS4V6YkEf4falA==/com.example.android.architecture.blueprints.reactive.test-K_x0_yJ0hJeDHaJkDmHXRw==/base.apk", zip file "/data/app/~~oeYx2MgTcILbk-vq_WPx1A==/com.example.android.architecture.blueprints.reactive-0wMHYEe95hx_1cnbdAoZAw==/base.apk"],nativeLibraryDirectories

It first occurred immediately after I added this code in the Fragment Test:

enter image description here

These are my relevant Libs on the Gradle:

enter image description here

I have these imports:

import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.hamcrest.core.IsNot.not

Answer

After struggling for a while I realized the error is being caused by espresso-contib and espresso-accessibility dependencies. My espresso version was the latest version 3.4.0-alpha05.

I removed them and tests passed.

Before including espresso-contrib & espresso-accessibility

/*core contains matches and view assertions, included by default on android project*/
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"

//testing code for advanced views such as recyclerview and Date picker
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$espressoVersion"

After comment out on both espresso-contrib & espresso-accessibility

//core contains matches and view assertions, included by default on android project
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
//testing code for advanced views such as recyclerview and Date picker
//androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
//androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$espressoVersion"
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..