UnsatisfiedLinkError (com.esri.core.runtime.LicenseImpl.nativeIsClientIdValid) [英] UnsatisfiedLinkError (com.esri.core.runtime.LicenseImpl.nativeIsClientIdValid)

查看:24
本文介绍了UnsatisfiedLinkError (com.esri.core.runtime.LicenseImpl.nativeIsClientIdValid)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设备中运行应用时发生错误:

Error occurred in running app in device:

    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:

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:

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 Studio 1.0.2 和 ArcGIS SDK 10.2.5

I use: Android Studio 1.0.2 and ArcGIS SDK 10.2.5

如果应用由 Android Studio 运行,则没有问题.如果应用在 APK 中生成,安装在设备中,然后运行,则会出现错误.

There is no problem if the app is run by Android Studio. Error occurred if the app is generated in APK, install in a device, and then run.

有什么解决办法吗?

非常感谢!

类似问题答案不起作用.

推荐答案

您的问题是 ProGuard.当您在发布模式下部署应用程序时,ProGuard 会启动并缩小您的所有方法/类/变量等.这意味着如果一个方法曾经被称为doSomething()",它将重命名为a()"之类的东西.这很好,因为当您的所有代码都发生这种情况时,它会使您的代码更小、更快.

Your issue is with ProGuard. When you deploy the app in release mode, ProGuard kicks in and minifies all your methods / classes / variables / etc. What this means is that if a method was once called "doSomething()", it will be renamed to something like "a()". This is good because when this happens on all your code, it makes your code smaller and faster.

这可能是使用 NDK 的问题,因为原生库与 Java 方法通信的方式是通过反射,这需要命名一致性(方法是通过文本名称找到的.如果名称更改,则找不到方法).

This can be a problem with working with the NDK, because the way a native library communicates with Java methods is via reflection, which requires naming consistency (methods are found by textual name. If the name changes, the method cannot be found).

您可以通过编辑 ProGuard 文件以排除某些类来解决此问题.

You can overcome this issue by editing your ProGuard file to exclude certain classes.

例如,在您的情况下,我会在您的 ProGuard 文件中添加以下行:

For example, in your case, I would add the following line in your ProGuard file:

-keep class com.esri.core.runtime.LicenseImpl { *; }

实际上,您可以使此规则更加具体以仅排除有问题的方法:

Actually, you can make this rule even more specific to only exclude the problematic method:

-keep class com.esri.core.runtime.LicenseImpl { 
    public void nativeIsClientIdValid(...);
}

ProGuard 在决定代码的哪些部分缩小或不缩小时非常强大,所以我建议 阅读它.

ProGuard is pretty powerful when it comes to deciding which portions of the code are minified or not, so I would suggest reading up on it.

可能还有其他类需要以类似的方式从 ProGuard 中排除,因此如果您在添加此修复程序后继续遇到类似错误,只需添加更多 ProGuard 规则,具体取决于哪些方法/类没有被排除找到了.

It is possible that there are other classes which need to be excluded from ProGuard in a similar way, so if you continue getting similar errors after adding this fix, simply add more ProGuard rules, depending on which methods / classes are not being found.

根据您收到的新错误,proguard 似乎正在重构注释,这可能是您的新错误的原因.添加以下标志以排除注释:

According to the new error you're getting, it seems proguard is refactoring annotations and this may likely be the cause of your new error. Add the following flag to exclude annotations:

-keepattributes *Annotation*

编辑 2:

根据这篇关于迁移项目的博客到 Esri 网站上的 Android studio,他们似乎还没有找到自己解决 ProGuard 问题的方法,因为他们建议将 enableMinify 设置为 false.这可能意味着 Esri 软件包此时根本无法使用缩小,或者他们没有投入时间来弄清楚如何解决问题.

According to this blog about migrating projects to Android studio in the Esri website, it seems that they have not yet found a way to overcome ProGuard issues themselves, as they recommend to set enableMinify to false. This could mean either that the Esri package simply does not working with minification at this time, or that they are haven't invested time in figuring out how to solve the issue.

这篇关于UnsatisfiedLinkError (com.esri.core.runtime.LicenseImpl.nativeIsClientIdValid)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆