java.lang.ClassNotFoundException: 在路径上找不到类 “eduapp.arg.MainApplication”

huangapple go评论89阅读模式
英文:

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

Adb Log

这是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>

AndroidManifest

这是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&#39;t find class &quot;eduapp.arg.MainApplication&quot; 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&#39;t find class &quot;eduapp.arg.MainApplication&quot; on path: DexPathList[[zip file &quot;/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/base.apk&quot;],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&#39;t find class &quot;eduapp.arg.MainApplication&quot; on path: DexPathList[[zip file &quot;/data/app/eduapp.arg-FAa3-QgPlP0Ej-TLlvTegw==/base.apk&quot;],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

Adb Log

Here I leave the Android Manifest.xml

&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; package=&quot;eduapp.arg&quot;&gt;
  &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.SYSTEM_ALERT_WINDOW&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.MANAGE_DOCUMENTS&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_INTERNAL_STORAGE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.USE_FINGERPRINT&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.VIBRATE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.MODIFY_AUDIO_SETTINGS&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_CONTACTS&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_CALENDAR&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_CALENDAR&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_SETTINGS&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot;/&gt;
  &lt;uses-permission android:name=&quot;com.google.android.c2dm.permission.RECEIVE&quot;/&gt;
  &lt;application android:name=&quot;.MainApplication&quot; android:label=&quot;@string/app_name&quot; android:icon=&quot;@mipmap/ic_launcher&quot; android:roundIcon=&quot;@mipmap/ic_launcher_round&quot; android:allowBackup=&quot;false&quot; android:theme=&quot;@style/AppTheme&quot;&gt;
    &lt;meta-data android:name=&quot;expo.modules.updates.EXPO_UPDATE_URL&quot; android:value=&quot;YOUR-APP-URL-HERE&quot;/&gt;
    &lt;meta-data android:name=&quot;expo.modules.updates.EXPO_SDK_VERSION&quot; android:value=&quot;37.0.0&quot;/&gt;
    &lt;meta-data android:name=&quot;expo.modules.updates.ENABLED&quot; android:value=&quot;true&quot;/&gt;
    &lt;meta-data android:name=&quot;expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH&quot; android:value=&quot;ALWAYS&quot;/&gt;
    &lt;meta-data android:name=&quot;expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS&quot; android:value=&quot;0&quot;/&gt;
    &lt;activity android:name=&quot;.MainActivity&quot; android:label=&quot;@string/app_name&quot; android:configChanges=&quot;keyboard|keyboardHidden|orientation|screenSize&quot; android:launchMode=&quot;singleTask&quot; android:windowSoftInputMode=&quot;adjustResize&quot; android:theme=&quot;@style/Theme.App.SplashScreen&quot; android:screenOrientation=&quot;portrait&quot;&gt;
      &lt;intent-filter&gt;
        &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;
        &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;
      &lt;/intent-filter&gt;
    &lt;/activity&gt;
    &lt;activity android:name=&quot;com.facebook.react.devsupport.DevSettingsActivity&quot;/&gt;
    &lt;activity
      android:name=&quot;com.theartofdev.edmodo.cropper.CropImageActivity&quot;
      android:theme=&quot;@style/Base.Theme.AppCompat&quot;&gt;
    &lt;/activity&gt;
  &lt;/application&gt;
&lt;/manifest&gt;

AndroidManifest

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&lt;ReactPackage&gt; getPackages() {
      List&lt;ReactPackage&gt; packages = new PackageList(this).getPackages();
      packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return &quot;index&quot;;
    }

    @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&#39;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&lt;?&gt; aClass = Class.forName(&quot;com.facebook.flipper.ReactNativeFlipper&quot;);
        aClass.getMethod(&quot;initializeFlipper&quot;, 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.

https://github.com/SasePriv/FrontEnd-EduApp/tree/expo-eject

答案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&#39;t find class &quot;eduapp.arg.MainApplication&quot; 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 &quot;com.example.myapp&quot;, an activity declared as &lt;activity android:name=&quot;.MainActivity&quot;&gt; 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.

huangapple
  • 本文由 发表于 2020年8月8日 11:45:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63311616.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定