在运行时出现此错误(显然不是唯一的错误):
6-25 14:30:00.016 28669-28669/com.augview.augviewdev E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.augview.augviewdev, PID: 28669
java.lang.NoSuchMethodError: No static method checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/com.augview.augviewdev-l2kpvmbk9RA-t7-vOPwQ6Q==/base.apk)
at com.augview.augview.AndroidLocation$1.run(AndroidLocation.java:86)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
这是我的gradle文件:
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 24
targetSdkVersion 27
versionCode 2
versionName "2.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
android.libraryVariants.all { variant ->
variant.outputs.all {
outputFileName = "AugviewAndroidPlugins.aar"
}
}
}
dependencies {
compileOnly files('libs/classes.jar')
implementation files('libs/sqlcipher.jar')
implementation 'com.android.support:support-v4:27.0.3'
}
这是崩溃的调用代码:
public void startLocationService(final double updateDistanceInMeters, final boolean highAccuracy) {
activity.runOnUiThread(new Runnable() {
public void run() {
boolean canUseFineLocation = ContextCompat.checkSelfPermission(activity, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED;
//... do some stuff
目前关于SO的解决方案建议将支持版本设置为我已经在做的27.x.x。我尝试用27.0.0和27.1.1替换'com.android.support:support-v4:27.0.3'的版本位,它们也可以编译,但在运行时也会崩溃。 谢谢 纪尧姆
答案 0 :(得分:0)
使用较新的版本更新classes.jar进行了修复。谢谢@madcode。
答案 1 :(得分:0)
请检查“ libs / classes.jar”,似乎问题与此文件有关。