Error inflating class com.esri.android.map.MapView

4924
5
Jump to solution
04-21-2014 07:50 AM
UmaraniPandian
New Contributor II
Hi,

   I'm using android studio for my application development. I tried adding MapView in my XML file and initialize it in my fragment class but I'm getting following exception.

My project structure:
[ATTACH=CONFIG]33227[/ATTACH]

My build.gradle:
apply plugin: 'android'  android {     compileSdkVersion 19     buildToolsVersion '19.0.1'      defaultConfig {         minSdkVersion 10         targetSdkVersion 19         versionCode 1         versionName "1.0"     }     buildTypes {         release {             runProguard false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'         }     } }  dependencies {     compile 'com.android.support:appcompat-v7:19.1.0'     compile 'com.android.support:support-v4:19.1.0'     compile 'com.google.android.gms:play-services:+'     compile fileTree(dir: 'libs', include: ['*.jar'])     compile files('libs/arcgis-android-api.jar')     compile files('libs/jackson-core-lgpl-1.9.5.jar')     compile files('libs/jackson-mapper-lgpl-1.9.5.jar')     compile files('libs/jcifs-1.3.17.jar') } android {     packagingOptions {         exclude 'META-INF/LGPL2.1'         exclude 'META-INF/DEPENDENCIES'         exclude 'META-INF/NOTICE'         exclude 'META-INF/LICENSE'         exclude 'META-INF/LICENSE.txt'         exclude 'META-INF/NOTICE.txt'     } }


My XML file:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:layout_height="match_parent">     <!-- MapView layout and initial extent -->      <com.esri.android.map.MapView         android:id="@+id/my_custom_map"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         initExtent = "-1.3296373526814876E7 3930962.41823043 -1.2807176545789773E7 4201243.7502468005">     </com.esri.android.map.MapView>  </FrameLayout>


My Frgament class:

@Override     public View onCreateView(LayoutInflater inflater, ViewGroup container,                              Bundle savedInstanceState) {         super.onCreateView(inflater,container,savedInstanceState);         // Inflate the layout for this fragment         Log.d("ON CREATEVIEW()","ON CREATEVIEW()");         meterGroupMapFragmentView = inflater.inflate(R.layout.map_arcgis, container, false);         mapView = (MapView)meterGroupMapFragmentView.findViewById(R.id.my_custom_map);         mapView.addLayer(new ArcGISTiledMapServiceLayer("" +                 "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));           return meterGroupMapFragmentView;     }
1 Solution

Accepted Solutions
UmaraniPandian
New Contributor II
@eric906 I was able to fix the error myself. My exception stack showed this.

06-26 16:36:15.678: E/AndroidRuntime(2672): Caused by: java.lang.reflect.InvocationTargetException 06-26 16:36:15.678: E/AndroidRuntime(2672): at java.lang.reflect.Constructor.constructNative(Native Method) 06-26 16:36:15.678: E/AndroidRuntime(2672): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 06-26 16:36:15.678: E/AndroidRuntime(2672): at android.view.LayoutInflater.createView(LayoutInflater.java:587) 06-26 16:36:15.678: E/AndroidRuntime(2672): ... 22 more 06-26 16:36:15.678: E/AndroidRuntime(2672): Caused by: java.lang.ExceptionInInitializerError 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.android.map.MapView.a(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.android.map.MapView.<init>(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): ... 25 more 06-26 16:36:15.678: E/AndroidRuntime(2672): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load runtimecore_java: findLibrary returned null 06-26 16:36:15.678: E/AndroidRuntime(2672): at java.lang.Runtime.loadLibrary(Runtime.java:365) 06-26 16:36:15.678: E/AndroidRuntime(2672): at java.lang.System.loadLibrary(System.java:535) 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.core.internal.util.e$1.initialize(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.android.io.a.a(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.android.map.MapSurface.<clinit>(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): ... 27 more


I was able to solve this by creating a jni folder in my app module and adding the .so files along with the folders into it and adding the following lines to my build.gradle file:

tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->     pkgTask.jniFolders = new HashSet<File>()     pkgTask.jniFolders.add(new File(buildDir, 'native-libs')) }   android {     packagingOptions {         exclude 'META-INF/LGPL2.1'         exclude 'META-INF/DEPENDENCIES'         exclude 'META-INF/NOTICE'         exclude 'META-INF/LICENSE'         exclude 'META-INF/LICENSE.txt'         exclude 'META-INF/NOTICE.txt'     } }

View solution in original post

0 Kudos
5 Replies
EricBader
Occasional Contributor III
Hello!

Can you share the exception stacktrace with us?

Thanks!
0 Kudos
UmaraniPandian
New Contributor II
@eric906 I was able to fix the error myself. My exception stack showed this.

06-26 16:36:15.678: E/AndroidRuntime(2672): Caused by: java.lang.reflect.InvocationTargetException 06-26 16:36:15.678: E/AndroidRuntime(2672): at java.lang.reflect.Constructor.constructNative(Native Method) 06-26 16:36:15.678: E/AndroidRuntime(2672): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 06-26 16:36:15.678: E/AndroidRuntime(2672): at android.view.LayoutInflater.createView(LayoutInflater.java:587) 06-26 16:36:15.678: E/AndroidRuntime(2672): ... 22 more 06-26 16:36:15.678: E/AndroidRuntime(2672): Caused by: java.lang.ExceptionInInitializerError 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.android.map.MapView.a(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.android.map.MapView.<init>(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): ... 25 more 06-26 16:36:15.678: E/AndroidRuntime(2672): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load runtimecore_java: findLibrary returned null 06-26 16:36:15.678: E/AndroidRuntime(2672): at java.lang.Runtime.loadLibrary(Runtime.java:365) 06-26 16:36:15.678: E/AndroidRuntime(2672): at java.lang.System.loadLibrary(System.java:535) 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.core.internal.util.e$1.initialize(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.android.io.a.a(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): at com.esri.android.map.MapSurface.<clinit>(Unknown Source) 06-26 16:36:15.678: E/AndroidRuntime(2672): ... 27 more


I was able to solve this by creating a jni folder in my app module and adding the .so files along with the folders into it and adding the following lines to my build.gradle file:

tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->     pkgTask.jniFolders = new HashSet<File>()     pkgTask.jniFolders.add(new File(buildDir, 'native-libs')) }   android {     packagingOptions {         exclude 'META-INF/LGPL2.1'         exclude 'META-INF/DEPENDENCIES'         exclude 'META-INF/NOTICE'         exclude 'META-INF/LICENSE'         exclude 'META-INF/LICENSE.txt'         exclude 'META-INF/NOTICE.txt'     } }
0 Kudos
VirenSavaliya
New Contributor
try this , Just right click on project  select -Arcgis tools ->convert Arcgis  android project.
0 Kudos
DanO_Neill
Occasional Contributor III
@umarani

You should be able to simplify your gradle build file. Local jar files go in the libs folder at the root of your module directory. In Android Studio you need to add the jars as a gradle dependency. This should have been added to your gradle build file as follows:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

}


You shouldn't need to create a task to include pre-built native libs. Local pre-built native libs go in the jniLibs folder in your modules /src/main/ folder. There is no need to add a gradle dependency when using this folder. Native libs outside this folder would require a gradle dependency.

[ATTACH=CONFIG]33499[/ATTACH]

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

    packagingOptions{
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'

}
UmaraniPandian
New Contributor II
Hi Dan, Thanks for the suggestion. I will follow this.
0 Kudos