mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
466 stars 131 forks source link

java.lang.UnsatisfiedLinkError: 'void com.mapbox.maps.assets.AssetManagerProvider.initialize(android.content.res.AssetManager)' #1788

Closed johnnyzen closed 1 year ago

johnnyzen commented 1 year ago

Android Studio: 2021.3.1 Patch 1 Mapbox: implementation 'com.mapbox.maps:android:10.9.0'

Getting error in preview layout window of android studio:

java.lang.UnsatisfiedLinkError: 'void com.mapbox.maps.assets.AssetManagerProvider.initialize(android.content.res.AssetManager)' at com.mapbox.maps.assets.AssetManagerProvider.initialize(Native Method) at com.mapbox.maps.MapController.<init>(MapController.kt:62) at com.mapbox.maps.MapView.<init>(MapView.kt:101) at com.mapbox.maps.MapView.<init>(MapView.kt:70) at com.mapbox.maps.MapView.<init>(MapView.kt:64) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:351) at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:200) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:161) at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:294) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:417) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:428) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:332) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1127) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.inflate(LayoutInflater.java:686) at android.view.LayoutInflater.inflate(LayoutInflater.java:505) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:359) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436) at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:717) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:873) at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:192) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829)

Cant seem to resolve, anyone else having same issue?

ZiZasaurus commented 1 year ago

@johnnyzen thank you for reporting. To better assist you, can you please let us know what's happening in the app or what actions you're taking, if any, before the error is thrown?

johnnyzen commented 1 year ago

Hi @ZiZasaurus

Sure, everything is working in the app when built, its just the preview layout in Android Studio not rendering with the error posted previously.

If I remove the layout:

<com.mapbox.maps.MapView android:id="@+id/map_view" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/map_view_button" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" mapbox:mapbox_cameraZoom="13.448986053466797" />

Android studio displays the layout.

I have created a new layout with just the mapview within a ConstraintLayout with same issue.

Hope this helps.

ZiZasaurus commented 1 year ago

@johnnyzen thank you for reaching out, It seems like there may be a mismatch between (or inability to load) the native libraries.

To better assist you, can you provide your android manifest?

MagicControl commented 1 year ago

Hi @ZiZasaurus! I have completely the same issue Mapbox maps both for 10.9.0 and 10.9.1 versions. Here is my project config: build.gradle (Module)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.example.agis'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.agis"
        minSdk 21
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.android.gms:play-services-maps:18.1.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    // Mapbox
    implementation 'com.mapbox.maps:android:10.9.1'
}

build.gradle (App)

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Agis"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
    </application>

</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.mapbox.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:mapbox_cameraTargetLat="40.7128"
        app:mapbox_cameraTargetLng="-74.0060"
        app:mapbox_cameraZoom="9.0" />

</androidx.constraintlayout.widget.ConstraintLayout>
johnnyzen commented 1 year ago

Here is my manifest:

` <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission
    android:name="android.permission.BLUETOOTH"
    android:maxSdkVersion="30" />
<uses-permission
    android:name="android.permission.BLUETOOTH_ADMIN"
    android:maxSdkVersion="30" />

<!-- These 2 bellow, only if you are targeting Android 12+ -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"
    tools:targetApi="s" />
<uses-permission
    android:name="android.permission.BLUETOOTH_SCAN"
    android:usesPermissionFlags="neverForLocation"
    tools:targetApi="s" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<!-- These 2 bellow, only if you are targeting Android 10+ -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-feature android:name="android.hardware.bluetooth" android:required="true"/>

<application
    android:name=".MainApplication"
    android:allowBackup="true"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.Green"
    android:hardwareAccelerated="true"
    tools:targetApi="31">

    <activity
        android:name=".ui.login.LoginActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".MainActivity"
        android:exported="true"/>

    <provider
        android:name="androidx.startup.InitializationProvider"
        android:authorities="${applicationId}.androidx-startup"
        android:exported="false"
        tools:node="merge">
        <meta-data
            android:name="com.initializer.to.be.removed"
            android:value="androidx.startup"
            tools:node="remove" />
    </provider>

</application>

`

hotellinawebmaster commented 1 year ago

Hello, I have the same error. image

java.lang.UnsatisfiedLinkError: 'void com.mapbox.maps.assets.AssetManagerProvider.initialize(android.content.res.AssetManager)' at com.mapbox.maps.assets.AssetManagerProvider.initialize(Native Method) at com.mapbox.maps.MapController.(MapController.kt:62) at com.mapbox.maps.MapView.(MapView.kt:101) at com.mapbox.maps.MapView.(MapView.kt:70) at com.mapbox.maps.MapView.(MapView.kt:64) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:351) at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:200) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:161) at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:294) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:417) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:428) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:332) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1127) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.inflate(LayoutInflater.java:686) at android.view.LayoutInflater.inflate(LayoutInflater.java:505) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:359) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436) at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:717) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:873) at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:192) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829)


activity_main.xml below

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Theme.SouvenirMaster.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/Theme.SouvenirMaster.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

<!--    <include layout="@layout/content_main" />-->
    <com.mapbox.maps.MapView
            xmlns:mapbox="http://schemas.android.com/apk/res-auto"
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            mapbox:mapbox_cameraTargetLat="40.7128"
            mapbox:mapbox_cameraTargetLng="-74.0060"
            mapbox:mapbox_cameraZoom="9.0" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

settings.gradle below

pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url 'https://api.mapbox.com/downloads/v2/releases/maven' authentication { basic(BasicAuthentication) } credentials { // Do not change the username below. // This should always be mapbox (not your username). username = "mapbox" // Use the secret token you stored in gradle.properties as the password password = "sk.****" } } } } } rootProject.name = "Souven*****" include ':app'

Julius-Babies commented 1 year ago

I have exactly the same problem with a new application. Whenever I add a MapView, the preview goes blank and I get this error. However, when I run the application on my device, the map displays fine. I have followed the steps from https://docs.mapbox.com/android/maps/guides/install/.

In #1173 the error occurs when you start the app, but here it occurs as soon as you add the MapView to the layout.

Is there an older version we can use until this error is fixed?

hotellinawebmaster commented 1 year ago

I believe this has never been fixed, as I never saw on Internet examples showing a preview in Android Studio.

Julius-Babies commented 1 year ago

But that's not very handy because you must remove the view whenever you want to edit the layout file. This solution sadly doesn't work.

Julius-Babies commented 1 year ago

Maybe useful for the developers: View.isInEditMode()

kiryldz commented 1 year ago

Thanks for heads up, will be fixed in v10.10.0 version available next week.

johnnyzen commented 1 year ago

@kiryldz Thank you Sir. Much respect.