简体   繁体   English

React Native java.lang.ClassNotFoundException:找不到类

[英]React Native java.lang.ClassNotFoundException: Didn't find class

The app crashes on device on start, this is the log:该应用程序在启动时在设备上崩溃,这是日志:

Note I replaced my original 'com.appname' with com.myappName注意我用 com.myappName 替换了我原来的 ' com.appname '

07-20 13:10:05.520  5376  5376 E AndroidRuntime: FATAL EXCEPTION: main
07-20 13:10:05.520  5376  5376 E AndroidRuntime: Process: com.myappName, PID: 5376
07-20 13:10:05.520  5376  5376 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate application com.myappName.MainApplication package com.myappName: java.lang.ClassNotFoundException: Didn't find class "com.myappName.MainApplication" on path: DexPathList[[zip file "/data/app/~~jMKAsYSvEjMZSEi2dXirHg==/com.myappName-u02x8yQYisyfG6ITJEv3UA==/base.apk"],nativeLibraryDirectories=[/data/app/~~jMKAsYSvEjMZSEi2dXirHg==/com.myappName-u02x8yQYisyfG6ITJEv3UA==/lib/x86_64, /data/app/~~jMKAsYSvEjMZSEi2dXirHg==/com.myappName-u02x8yQYisyfG6ITJEv3UA==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]]
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1463)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1392)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6740)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:106)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:201)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:288)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7892)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
07-20 13:10:05.520  5376  5376 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myappName.MainApplication" on path: DexPathList[[zip file "/data/app/~~jMKAsYSvEjMZSEi2dXirHg==/com.myappName-u02x8yQYisyfG6ITJEv3UA==/base.apk"],nativeLibraryDirectories=[/data/app/~~jMKAsYSvEjMZSEi2dXirHg==/com.myappName-u02x8yQYisyfG6ITJEv3UA==/lib/x86_64, /data/app/~~jMKAsYSvEjMZSEi2dXirHg==/com.myappName-u02x8yQYisyfG6ITJEv3UA==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]]
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.Instrumentation.newApplication(Instrumentation.java:1232)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1455)
07-20 13:10:05.520  5376  5376 E AndroidRuntime:    ... 11 more

It used to work fine before both on Mac and here on Linux.它以前在 Mac 和 Linux 上都可以正常工作。 After installing fresh Linux distro and cloning the git repository, this started happening安装新的 Linux 发行版并克隆 git 存储库后,这开始发生

Here is what I did:这是我所做的:

  1. Cloned git repository克隆的 git 存储库
  2. npm install --save-exact npm install --save-exact
  3. React Native enviroment / Android is set up properly - no errors regarding that React Native 环境/Android 设置正确 - 没有错误

android/app/build.gradle android/app/build.gradle

    defaultConfig {
        applicationId "com.myappName"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 20
        versionName "2.0"
    }

/android/app/src/main/AndroidManifest.xml /android/app/src/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.myappName">

    <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|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
    </application>
</manifest>

Emulator is Resizeable API 33 x86_64模拟器是可调整大小的 API 33 x86_64

Thanks谢谢

检查您的 MainActivity.java 和 MainApplication.java 文件的第一行,它应该是com.myappName

I was missing Java files.我缺少 Java 文件。 Fixed the issue by rebuilding android and ios folders with react-native-eject通过使用react-native-eject重建androidios文件夹修复了该问题

npm install react-native-eject
sudo rm -rf android ios
npx react-native eject

Make sure to replace package name manually in .java files afterwards.确保之后在.java文件中手动替换包名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassNotFoundException:在路径:DexPathList上找不到类… - java.lang.ClassNotFoundException: Didn't find class … on path: DexPathList java.lang.ClassNotFoundException:在路径上找不到 class:dexpathlist - java.lang.ClassNotFoundException: Didn't find class on path: dexpathlist 原因:java.lang.ClassNotFoundException:在路径上找不到类 - Caused by: java.lang.ClassNotFoundException: Didn't find class on path java.lang.ClassNotFoundException:找不到带有TeamCity构建的类 - java.lang.ClassNotFoundException: Didn't find class with TeamCity build java.lang.ClassNotFoundException:找不到类“ java.lang.Character $ UnicodeScript” - java.lang.ClassNotFoundException: Didn't find class “java.lang.Character$UnicodeScript” java.lang.RuntimeException:无法实例化活动ComponentInfo {...}:java.lang.ClassNotFoundException:未找到类 - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{…}: java.lang.ClassNotFoundException: Didn't find class 膨胀 class android.view.InflateException 时出错,未找到 class Z93F725A07423FE1C886F448B。 - Error inflating class android.view.InflateException, Didn't find class java.lang.ClassNotFoundException java.lang.ClassNotFoundException:没有找到 class “java.util.Base64” - java.lang.ClassNotFoundException: Didn't find class “java.util.Base64” 由java.lang.ClassNotFoundException引起找不到类“ com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver - Caused by java.lang.ClassNotFoundException Didn't find class "com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver java.lang.ClassNotFoundException:找不到类“ com.life.Life” - java.lang.ClassNotFoundException: Didn't find a class “com.life.Life”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM