Android app ClassNotFoundException for main activity

后端 未结 12 674
灰色年华
灰色年华 2020-12-06 10:07

Most of the devices can run my app but I got this error report :

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.company.app/com         


        
12条回答
  •  长情又很酷
    2020-12-06 10:30

    I had this problem for the last couple days. I could run my app on every test environment, I could export a release apk, and install and run it on every test environment, but when I uploaded the apk to the play store and installed from the play store the app would fource close throwing ClassNotFoundException. It turned out that in my project I was sending multipart form data to a web api, and to do this requires some external libraries. At first I just included all the mim4j, httpclient, and httpcore .jars (turns out to be a lot of jars).

    After deleting almost all of them one by one and seeing if my project would still build I was left with only one jar THAT WAS ACTUALLY REQUIRED. The take away is delete any jars that are not required to build. Then I tested the app and turns out I needed to add one of the jars back because it's resources were referenced by the one that was required to build the project. Make sure to test every function of your app after deleting jars.

    Then I went through each library project I was including and went to right-click on project -> properties -> java build path -> order and export and checked all the boxes FOR EVERY LIBRARY and MY OWN PACKAGE.

    Then I did a project -> clean on every project that is included and the main project.

    Then I exported the apk and put the package up for beta testing and it finally worked on users devices.

提交回复
热议问题