当我将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)
中逐字地看到这些库
自从过去2天以来我一直坚持这一点,并且不知道还有什么办法可以解决这个问题。