UnsatisfiedLinkError (com.esri.core.runtime.LicenseImpl.nativeIsClientIdValid)
Asked Answered
F

4

7

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)

Related code:

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

I use: Android Studio 1.0.2 and ArcGIS SDK 10.2.5

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.

Is there any solution?

Thank you very much!

Similar question The answer does not work.

Fungible answered 23/2, 2015 at 3:40 Comment(9)
Please post your code (including the native code)Fumatorium
I got the same error When I am using SONIC-NDK. This error occurs when so file is missing..Stopper
related code included.Fungible
Look like you have missed native libraries. Please check whether you have included .so files of ArcGIS SDK 10.2.5.Bircher
can you tell me how to check? the app can be run by Android Studio. thanks.Fungible
Are you running ProGuard/Minify in your build.gradle?Vespertilionine
Yes, build.gradle is included. After commenting the line "minifyEnabled true", the error disappeared. However, ProGuard is needed for shrinking and obfuscating the code in apk. Any other setting I can try?Fungible
To check if .so is there in apk: an apk is a zip archive, it maybe unpacked or viewed with, say, MidnightCommander (mc) or Far Manager. For example, unzip -l OneLib.apk shows me, among other stuff, lib/armeabi-v7a/libone.so (and no lib/armeabi/libone.so which means that my apk will not work on non-v7a devices)Aerification
Thanks. The file libruntimecore_java.so is in apk. (lib/armeabi, lib/armeabi-v7a, lib/x86)Fungible
J
2

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.

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).

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

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 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.

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.

Edit:

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*

Edit 2:

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.

Jennettejenni answered 3/3, 2015 at 9:37 Comment(4)
Thanks. proguard-rules.txt is included in the question. The app now cannot view the map. It just shows a black area. Logcat is also included. Is it related to NoSuchFieldError?Fungible
It looks like there's an issue with annotations. Please see my edit.Jennettejenni
After adding the line "-keepattributes Annotation", same error occurred. Thanks for the blog link, I agree that esri may not support proguard. So...... maybe I have to give up and set "minifyEnabled" to "false"......Fungible
Or perhaps consider using a different package :/ Maybe they'll fix this soon.Jennettejenni
D
1

Add this to your proguard file. This will not apply obfuscation to your library

-keep class com.esri.** { *; }
-keep interface com.esri.** { *; }
Diestock answered 4/3, 2015 at 14:21 Comment(0)
U
1
-keep class com.esri.** { *; }
-keep interface com.esri.** { *; }
-keep class org.codehaus.jackson.** { *; }
-dontwarn org.codehaus.jackson.map.ext.**
-dontwarn jcifs.http.**

worked for me.

Ubangishari answered 17/12, 2015 at 13:35 Comment(1)
Thank you so much! you saved my life! I was working on it since days!! Finally your solution worked.Simultaneous
I
0

I had the same issue and solved as explained in this link on Esri GeoNet.

Based on what EsriStaff wrote:

Yes, I agree that this is most likely what's happening. I can see in the path above that arm64 paths are involved, and also there was a comment above that things work OK, until another dependency is added. Given those two points, it's very possible you're running in to the problem where once Android has loaded a 64-bit native library, it no longer loads 32-bit libraries. [...] The ArcGIS Runtime SDK provides 32-bit armeabi-v7a library, which would normally be loaded when running on 64 bit, as its forwardly compatible, which would explain why you're finding things OK until you add more dependencies.

As the SO question linked in EsriGeoNet suggests the solution is to add this inside your app.gradle file:

android {
    ....
    defaultConfig {
        ....
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
}

At this point running the gradle build should give you a NDK deprecated integration error that you can solve by adding this inside your gradle.properties (Global properties) file:

android.useDeprecatedNdk = true

I've tested on a Samsung S6 with Android 6.0.1 and works fine.

In addition to this I've found out that the issue was already there in ArcGis Android SDK v10.2.3 and that upgrading to the latest v10.2.8.1 does not fix the issue.

Next week our staff has a scheduled meeting with Esri Italian office and I'll ask details about this bug and if / when it is going to be fixed.

Hope this helps you and anyone else having this issue.

Irregular answered 30/9, 2016 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.