没找到类" android.support.v4.content.ContextCompat"甚至在添加所有库之后

时间:2017-03-09 23:22:59

标签: android permissions

当我将targetSDK更改为大于22时,编译器不允许直接使用权限。权限必须由用户提供,我必须使用以下代码:

if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                MY_PERMISSSIONS_REQUEST_FINE_LOCATION);

 }

但我一直收到以下错误

Didn't find class "android.support.v4.content.ContextCompat"

我已经为ContextCompat和ActivityCompat添加了所有必需的文件,但每次都会出现此错误。这是我的build.gradle

[编辑]添加整个gradle文件

apply plugin: 'com.android.library'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"

        defaultConfig {
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"

            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        }
        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.2.0'
        compile files('libs/classes.jar')
        compile 'com.android.support:support-v4:25.2.0'
    }

    //task to delete the old jar
    task deleteOldJar(type: Delete) {
        delete '/Users/kushagragupta/Desktop/Kushagra/STURFEE/Sturfee.Unity.Mobile.IMUGPSTest/Assets/AndroidPlugin.jar'
    }

    //task to export contents as jar
    task exportJar(type: Copy) {
        from('build/intermediates/bundles/release/')
        into('/Users/kushagragupta/Desktop/Kushagra/STURFEE/Sturfee.Unity.Mobile.IMUGPSTest/Assets/')
        include('classes.jar')
        ///Rename the jar
        rename('classes.jar', 'AndroidPlugin.jar')
    }

    exportJar.dependsOn(deleteOldJar, build)

我可以在Android Studio enter image description here

中逐字地看到这些库

自从过去2天以来我一直坚持这一点,并且不知道还有什么办法可以解决这个问题。

1 个答案:

答案 0 :(得分:1)

我在support-v4-25.2.0中发现的是,Android SDK附带的.aar看起来或多或少是空的,只有2KB大小。进一步看,我看到所有返回到24.1.1的.aar文件大小只有2KB。 enter image description here

我可以使用版本24.1.1解决它。