在设备中运行应用程序时出错:
java.lang.UnsatisfiedLinkError: Native method not found: com.esri.core.runtime.LicenseImpl.nativeIsClientIdValid:(Ljava/lang/String;)Z
at com.esri.core.runtime.LicenseImpl.nativeIsClientIdValid(Native Method)
at com.esri.core.runtime.LicenseImpl.a(Unknown Source)
at com.esri.android.a.b.b(Unknown Source)相关代码:
import com.esri.android.runtime.ArcGISRuntime;
public class MainActivity extends FragmentActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArcGISRuntime.setClientId("xxxxxxxxxxxxxxxx");
......build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "xxx.xxxx.xxxxx"
minSdkVersion 17
targetSdkVersion 19
versionCode 1
versionName "1.0"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, "xxxx-release.apk")
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}proguard-rules.txt:
-keep class android.view.** { *; }
-keep class com.esri.** { *; }
-keep class javax.servlet.** { *; }
-keep class jcifs.http.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.joda.time.** { *; }
-keep class org.w3c.dom.bootstrap.** { *; }
-keep class org.xmlpull.v1.** { *; }
-dontwarn javax.servlet.**
-dontwarn jcifs.http.**
-dontwarn org.apache.http.**
-dontwarn org.joda.time.**
-dontwarn org.w3c.dom.bootstrap.**
-dontwarn org.xmlpull.v1.**Logcat:
03-04 18:06:19.213 13255-13255/xxx.xxxx.xxxxx D/dalvikvm﹕ GC_FOR_ALLOC freed 360K, 17% free 35228K/42136K, paused 17ms, total 17ms
03-04 18:06:19.283 13255-13255/xxx.xxxx.xxxxx D/dalvikvm﹕ GC_FOR_ALLOC freed 368K, 16% free 35516K/42136K, paused 14ms, total 14ms
03-04 18:06:19.343 13255-13753/xxx.xxxx.xxxxx D/dalvikvm﹕ GC_FOR_ALLOC freed 408K, 15% free 35859K/42136K, paused 14ms, total 14ms
03-04 18:06:19.353 13255-13753/xxx.xxxx.xxxxx W/dalvikvm﹕ Failed processing annotation value
03-04 18:06:19.353 13255-13753/xxx.xxxx.xxxxx W/dalvikvm﹕ Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lorg/b/a/d/e/z;
03-04 18:06:19.353 13255-13753/xxx.xxxx.xxxxx W/dalvikvm﹕ Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lorg/b/a/d/an;
03-04 18:06:19.353 13255-13753/xxx.xxxx.xxxxx W/dalvikvm﹕ Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lcom/esri/core/internal/util/d;
03-04 18:06:19.353 13255-13754/xxx.xxxx.xxxxx I/dalvikvm﹕ Rejecting re-init on previously-failed class Lcom/esri/core/internal/util/d; v=0x0
03-04 18:06:19.423 13255-13255/xxx.xxxx.xxxxx D/dalvikvm﹕ GC_FOR_ALLOC freed 776K, 15% free 35950K/42136K, paused 14ms, total 14ms
03-04 18:06:19.443 13255-13756/xxx.xxxx.xxxxx I/dalvikvm﹕ Rejecting re-init on previously-failed class Lcom/esri/core/internal/util/d; v=0x0
03-04 18:06:19.453 13255-13755/xxx.xxxx.xxxxx I/dalvikvm﹕ Rejecting re-init on previously-failed class Lcom/esri/core/internal/util/d; v=0x0我使用: Android Studio1.0.2和ArcGIS SDK10.2.5
如果该应用程序是由Android Studio运行的,则没有问题。APK生成app,在设备上安装后再运行,出错。
有什么解决方案吗?
非常感谢!
Similar question答案不起作用。
发布于 2015-03-03 17:37:58
您的问题与ProGuard有关。当你在发布模式下部署应用程序时,ProGuard会启动并缩小你所有的方法/类/变量/等等。这意味着如果一个方法曾经被称为"doSomething()",它将被重命名为类似"a()“的名称。这很好,因为当所有代码都发生这种情况时,它会使您的代码变得更小、更快。
这对于使用NDK可能是一个问题,因为本地库与Java方法的通信方式是通过反射,这需要命名一致性(方法是通过文本名称找到的。如果名称更改,则无法找到该方法)。
您可以通过编辑ProGuard文件以排除某些类来解决此问题。
例如,在您的示例中,我将在ProGuard文件中添加以下行:
-keep class com.esri.core.runtime.LicenseImpl { *; }实际上,您可以将此规则设置得更具体,只排除有问题的方法:
-keep class com.esri.core.runtime.LicenseImpl {
public void nativeIsClientIdValid(...);
}在决定代码的哪些部分是否缩小时,ProGuard非常强大,所以我建议使用reading up on it.
可能还有其他类需要以类似的方式从ProGuard中排除,所以如果在添加此修复后仍然收到类似的错误,只需添加更多的ProGuard规则,这取决于没有找到哪些方法/类。
编辑:
根据你得到的新错误,proguard似乎正在重构注释,这可能是你新错误的原因。添加以下标记以排除注释:
-keepattributes *Annotation*编辑2:
根据this blog about migrating projects to Android studio in the Esri website的说法,他们似乎还没有找到解决ProGuard问题的方法,因为他们建议将enableMinify设置为false。这可能意味着Esri包目前根本不能与最小化一起工作,或者他们还没有投入时间来解决这个问题。
发布于 2015-03-04 22:21:13
将其添加到您的proguard文件中。这将不会将模糊处理应用于您的库
-keep class com.esri.** { *; }
-keep interface com.esri.** { *; }发布于 2015-12-17 21:35:12
-keep class com.esri.** { *; }
-keep interface com.esri.** { *; }
-keep class org.codehaus.jackson.** { *; }
-dontwarn org.codehaus.jackson.map.ext.**
-dontwarn jcifs.http.**对我很管用。
https://stackoverflow.com/questions/28666583
复制相似问题