我们如何解决检查自我许可错误 Android
How we resolve Check self permission error Android
"checkSelfPermission" 向我显示错误我尝试读取堆栈上的许多内容仍然无法解决此问题
if (ContextCompat.checkSelfPermission(this ,Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED)
{
}
-
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.googlemap"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compile 'com.android.support:appcompat-v7:26.0.0'
compile 'androidx.appcompat:appcompat:1.0.0'
compile 'com.google.android.gms:play-services:8.4.0'
testCompile 'junit:junit:4.12'
}
上面一行也显示错误
请将所有依赖项升级到 Android 对应项。
其次,不要使用 compile
- 请改用 implementation
。
改变
testCompile 'junit:junit:4.12'
到
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
同样,将所有依赖项升级到最新的 Android 库。
主要问题是依赖类型冲突。您正在使用 androidx 和同一库的旧支持类型。这里有两个可以帮助您的快速修复方法:
将所有依赖项更改为 Android。为此,您可以左键单击依赖项并选择 migrate to AndroidX。另外,删除重复的依赖项;不需要支持 app-compat 依赖项。
在您的 Gradle 文件中将 compile
更改为 implementation
。同时将 testCompile
更改为 testImplementation
.
希望对您有所帮助。
"checkSelfPermission" 向我显示错误我尝试读取堆栈上的许多内容仍然无法解决此问题
if (ContextCompat.checkSelfPermission(this ,Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED)
{
}
-
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.googlemap"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compile 'com.android.support:appcompat-v7:26.0.0'
compile 'androidx.appcompat:appcompat:1.0.0'
compile 'com.google.android.gms:play-services:8.4.0'
testCompile 'junit:junit:4.12'
}
上面一行也显示错误
请将所有依赖项升级到 Android 对应项。
其次,不要使用 compile
- 请改用 implementation
。
改变
testCompile 'junit:junit:4.12'
到
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
同样,将所有依赖项升级到最新的 Android 库。
主要问题是依赖类型冲突。您正在使用 androidx 和同一库的旧支持类型。这里有两个可以帮助您的快速修复方法:
将所有依赖项更改为 Android。为此,您可以左键单击依赖项并选择 migrate to AndroidX。另外,删除重复的依赖项;不需要支持 app-compat 依赖项。
在您的 Gradle 文件中将
compile
更改为implementation
。同时将testCompile
更改为testImplementation
.
希望对您有所帮助。