skip to Main Content

I have recently upgraded my React Native app to version 0.73.0 which also includes switching from Java to Kotlin for MainActivity and MainApplication classes.

Now when I try to run the app, I get the following error:

java.lang.RuntimeException: Unable to instantiate application xxx.xxx.xxx.MainApplication package xxx.xxx.xxx: java.lang.ClassNotFoundException: Didn’t find class "xxx.xxx.xxx.MainApplication" on path: DexPathList

How can I resolve this?

2

Answers


  1. Chosen as BEST ANSWER

    OK. After spending a couple of hours I finally figured out how to fix this. This is not mentioned in React Native 0.73.0 upgrade documentation.

    So, in order to get the project working, you need to take the following steps after your actual RN upgrade:

    1. Open your project-level build.gradle and add include kotlinVersion = '1.9.0'
    2. Add google() in the buildscript.repositories and allprojects in the same build.gralde file.
    3. Add classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}" in the dependencies.
    4. Do a Sync.
    5. open up the build.grdle file inside the app folder and add apply plugin: "kotlin-android" at the top of the file.
    6. In the dependencies section add the following dependency: implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0".
    7. Do a Sync.

    Now your project will run correctly.


  2. After some additional testing today, I’ve found out that my issue is something with the new Kotlin files (MainActivity, MainApplication).

    I’ve followed the React Native Upgrade Helper file by file since the npx upgrade failed, and what I’ve noticed is that my application will build successfully agaon once I revert the file extensions to .java instead of .kt. Even though I’ve updated the code inside the both files from RN Upgrade Helper, with the minimal custom code (in my case for Bootsplash screen and RN Screens).

    This should be the temporary solution only, because the main change of this version is switching to Kotlin for Android, we should see how the next minor version can affect this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search