【问题标题】:java.lang.ClassNotFoundException: Didn't find class … on path: DexPathListjava.lang.ClassNotFoundException:在路径上找不到类...:DexPathList
【发布时间】:2019-03-26 01:20:03
【问题描述】:

我正在尝试为 android 构建 SFML 应用程序,但遇到了一些奇怪的错误。 首先,我的应用是这样配置的:

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := sfml-example

LOCAL_SRC_FILES := main.cpp

LOCAL_SHARED_LIBRARIES := sfml-system
LOCAL_SHARED_LIBRARIES += sfml-window
LOCAL_SHARED_LIBRARIES += sfml-graphics
LOCAL_SHARED_LIBRARIES += sfml-audio
LOCAL_SHARED_LIBRARIES += sfml-network
LOCAL_SHARED_LIBRARIES += sfml-activity
LOCAL_SHARED_LIBRARIES += openal
LOCAL_WHOLE_STATIC_LIBRARIES := sfml-main

include $(BUILD_SHARED_LIBRARY)

$(call import-module,third_party/sfml)

Application.mk

NDK_TOOLCHAIN_VERSION := 4.9
APP_PLATFORM := android-19
APP_STL := c++_static
APP_ABI := all
APP_MODULES := sfml-activity sfml-example
APP_OPTIM := release
APP_CFLAG := -g -O3

它已在 Android 5、6、7 上编译并运行良好。但是当我尝试在 android 6.0 上启动应用程序时出现错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{org.sfml_test.android/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/org.sfmldev.android-1/lib/arm/libsfml-activity.so

我在this 问题中发现了类似的问题。 所以我尝试编写应该加载 SFML 库的活动。活动代码:

package org.sfmldev.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


public class SFMLLoader  extends Activity {
    static {
        System.loadLibrary("sfml-activity");
        System.loadLibrary("sfml-example");
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(SFMLLoader.this, android.app.NativeActivity.class);
        SFMLLoader.this.startActivity(intent);
    }
}

我更改了我的 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"
    package="org.sfmldev.android">

    <uses-feature android:glEsVersion="0x00010001" />

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


    <application android:label="@string/app_name"
                 android:icon="@drawable/sfml_logo"
                 android:hasCode="false"
                 android:allowBackup="false"
                 android:testOnly="false"
        tools:ignore="GoogleAppIndexingWarning">

        <activity android:name="org.sfmldev.android.SFMLLoader"
            android:label="@string/app_name"
            android:configChanges="keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="android.app.NativeActivity"
              android:label="@string/app_name"
              android:icon="@drawable/sfml_logo"
              android:configChanges="keyboardHidden|orientation|screenSize">

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

    </activity>
    </application>
</manifest>

现在我在任何设备上都有新错误:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.sfmldev.android/org.sfmldev.android.SFMLLoader}: java.lang.ClassNotFoundException: Didn't find class "org.sfmldev.android.SFMLLoader" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

我已经尝试过创建相对路径,禁用实例运行,清理项目,重启android studio,重启操作系统,删除.idea和.gradle

【问题讨论】:

    标签: android android-ndk native sfml


    【解决方案1】:

    您应该在运行时而不是在活动创建时加载库:

    public class SFMLLoader extends Activity {
        static {
            System.loadLibrary("sfml-activity");
            System.loadLibrary("sfml-example");
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ...
        }
    }
    

    【讨论】:

      【解决方案2】:

      只是忘记从 AndroidManifest.xml

      中删除 android:hasCode="false"

      【讨论】:

        猜你喜欢
        • 2014-04-19
        • 2017-03-16
        • 2017-12-23
        • 2018-04-13
        • 2019-07-02
        • 1970-01-01
        • 1970-01-01
        • 2016-06-25
        相关资源
        最近更新 更多