英文:
java.lang.ClassNotFoundException: Didn't find class "eduapp.arg.MainApplication" on path: DexPathList
问题
这是一个使用React Native制作的应用程序,首先使用Expo创建,然后进行了eject操作。当我尝试构建应用程序时,它没有出现任何错误,但在安装和运行时崩溃,应用程序立即关闭并显示错误。
使用adb logcat工具查看手机日志,并显示以下信息:
无法实例化应用程序eduapp.arg.MainApplication:java.lang.ClassNotFoundException:在路径上找不到类"eduapp.arg.MainApplication":DexPathList
08-07 02:32:48.585 10182 10182 E AndroidRuntime: 严重错误:主进程中的异常
08-07 02:32:48.585 10182 10182 E AndroidRuntime: 进程:eduapp.arg,PID:10182
08-07 02:32:48.585 10182 10182 E AndroidRuntime: java.lang.RuntimeException: 无法实例化应用程序eduapp.arg.MainApplication:java.lang.ClassNotFoundException:在路径上找不到类"eduapp.arg.MainApplication":DexPathList[[zip文件"/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/base.apk"],nativeLibraryDirectories=[/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/lib/arm64,/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/base.apk!/lib/arm64-v8a,/system/lib64]]
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:1073)
...
这是AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="eduapp.arg">
<uses-permission android:name="android.permission.INTERNET"/>
...
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
...
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
...
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity" android:theme="@style/Base.Theme.AppCompat">
</activity>
</application>
</manifest>
这是MainApplication.java:
package com.frontendeduapp;
import android.app.Application;
import android.content.Context;
import android.net.Uri;
...
public class MainApplication extends Application implements ReactApplication {
...
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this); // 如果不想启用Flipper,请删除此行
if (!BuildConfig.DEBUG) {
UpdatesController.initialize(this);
}
}
...
}
如果需要查看完整项目,请访问GitHub链接:https://github.com/SasePriv/FrontEnd-EduApp/tree/expo-eject
英文:
This is a react native application made first with expo and then ejected. When I want to perform the build it does not give any error but when installing and running it crashes, the app never always closes at once and shows an error.
Using the adb logcat tool to see the phone log and show me this:
Unable to instantiate application eduapp.arg.MainApplication: java.lang.ClassNotFoundException: Didn't find class "eduapp.arg.MainApplication" on path: DexPathList
08-07 02:32:48.585 10182 10182 E AndroidRuntime: FATAL EXCEPTION: main
08-07 02:32:48.585 10182 10182 E AndroidRuntime: Process: eduapp.arg, PID: 10182
08-07 02:32:48.585 10182 10182 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate application eduapp.arg.MainApplication: java.lang.ClassNotFoundException: Didn't find class "eduapp.arg.MainApplication" on path: DexPathList[[zip file "/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/base.apk"],nativeLibraryDirectories=[/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/lib/arm64, /data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/base.apk!/lib/arm64-v8a, /system/lib64]]
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:1073)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5920)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.ActivityThread.access$1200(ActivityThread.java:200)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.os.Looper.loop(Looper.java:201)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6810)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "eduapp.arg.MainApplication" on path: DexPathList[[zip file "/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/base.apk"],nativeLibraryDirectories=[/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/lib/arm64, /data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/base.apk!/lib/arm64-v8a, /system/lib64]]
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:47)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.Instrumentation.newApplication(Instrumentation.java:1121)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:1065)
08-07 02:32:48.585 10182 10182 E AndroidRuntime: ... 9 more
08-07 02:32:48.591 2038 3384 W ActivityManager: Force finishing activity eduapp.arg/.MainActivity
Here I leave the Android Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="eduapp.arg">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="YOUR-APP-URL-HERE"/>
<meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="37.0.0"/>
<meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat">
</activity>
</application>
</manifest>
Here is the MainApplication.java
package com.frontendeduapp;
import android.app.Application;
import android.content.Context;
import android.net.Uri;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.facebook.react.BuildConfig;
import com.frontendeduapp.generated.BasePackageList;
import org.unimodules.adapters.react.ReactAdapterPackage;
import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.interfaces.Package;
import org.unimodules.core.interfaces.SingletonModule;
import expo.modules.constants.ConstantsPackage;
import expo.modules.permissions.PermissionsPackage;
import expo.modules.filesystem.FileSystemPackage;
import expo.modules.updates.UpdatesController;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
public class MainApplication extends Application implements ReactApplication {
private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(
new BasePackageList().getPackageList()
);
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
return packages;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
@Override
protected @Nullable String getJSBundleFile() {
if (BuildConfig.DEBUG) {
return super.getJSBundleFile();
} else {
return UpdatesController.getInstance().getLaunchAssetFile();
}
}
@Override
protected @Nullable String getBundleAssetName() {
if (BuildConfig.DEBUG) {
return super.getBundleAssetName();
} else {
return UpdatesController.getInstance().getBundleAssetName();
}
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this); // Remove this line if you don't want Flipper enabled
if (!BuildConfig.DEBUG) {
UpdatesController.initialize(this);
}
}
/**
* Loads Flipper in React Native templates.
*
* @param context
*/
private static void initializeFlipper(Context context) {
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
I leave the github link if you want to see the complete project.
答案1
得分: 1
从日志中得知:无法实例化应用程序 eduapp.arg.MainApplication: java.lang.ClassNotFoundException: 在路径上找不到类 "eduapp.arg.MainApplication"
根据Android开发者文档之一,AndroidManifest中的package
属性的用途之一是:
...用于解析在清单文件中声明的任何相对类名。
例如,如果将package设置为"com.example.myapp",则声明为<activity android:name=".MainActivity">的活动将解析为com.example.myapp.MainActivity
因此,您的MainApplication位于包com.frontendeduapp
中,但您在AndroidManifest中定义了包名为eduapp.arg
。因此,在构建您的应用程序时,package
的值被用于将相对的.MainApplication
转换为eduapp.arg.MainApplication
,而实际上应该是com.frontendeduapp.MainApplication
。
解决方法是将AndroidManifest中的eduapp.arg
替换为com.frontendeduapp
,然后重新构建。
英文:
From the logs: Unable to instantiate application eduapp.arg.MainApplication: java.lang.ClassNotFoundException: Didn't find class "eduapp.arg.MainApplication" on path
From the Android Developer docs, one of the uses for the package
attribute in AndroidManifest is:
...to resolve any relative class names that are declared in the manifest file.
For example, if package is set to "com.example.myapp", an activity declared as <activity android:name=".MainActivity"> is resolved to be com.example.myapp.MainActivity
So, your MainApplication is in package com.frontendeduapp
, yet you defined the package in your AndroidManifest as eduapp.arg
. So now when building your app, that value for package
is used to turn your relative .MainApplication
into eduapp.arg.MainApplication
when really it should be com.frontendeduapp.MainApplication
.
Solution is to replace eduapp.arg
with com.frontendeduapp
in your AndroidManifest and rebuild.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论