Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
756 views
in Technique[技术] by (71.8m points)

android - Cannot access ActivityCompatApi23 class

I am having runtime problems with my gradle file. I added this compile 'com.google.android:flexbox:0.3.1' as a compile time dependency to my Gradle file. I encountered an error and added this in my project level Gradle file.

maven {
            url "https://maven.google.com"
        }

Which finally looked liked this after adding the above

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

After adding the above in my app level Gradle file I am now encountering a different error when I am trying to run my app. So I did the following as per some answers from SO.

  1. Tried a Clean and Rebuild.
  2. Navigated to the path projectName.idealibraries and deleted the files that contained the support library version other than the current versions 25.3.1 3.In order to solve the error I further removed this line from my app level Gradle file,

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' })

Now the final Gradle file looks like this with the error,

Error:

Error:(28, 8) error: cannot access ActivityCompatApi23
class file for android.support.v4.app.ActivityCompatApi23 not found

My Gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.google.android:flexbox:0.3.1'
    compile 'uk.co.chrisjenx:calligraphy:2.3.0'
    testCompile 'junit:junit:4.12'
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Like the Problem I meet。

When I Use Android Room like this :

compileSdkVersion 25 compile "android.arch.persistence.room:runtime:1.0.0"

I get the same Error.

Because compileSdkVersion should match support libs major version.

More Detail you can see this : Error in support lib after room persistence

Room depends on 26.1 of support library, which is probably why it is broken because SupportLibrary does not promise interop between versions.

Also, you can fix the problem use this

compile ("android.arch.persistence.room:runtime:1.0.0") {
                exclude group: 'com.android.support'
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...