0

I'm to trying create an application with package name "com.cvs.myapp". App builds perfectly but crashes in device at runtime.

    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.cvs.myapp/com.cvs.myapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.cvs.myapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.cvs.myapp-DG6fxWRjVXjsKQV_vwJwAw==/base.apk"],nativeLibraryDirectories=[/data/app/com.cvs.myapp-DG6fxWRjVXjsKQV_vwJwAw==/lib/x86, /system/lib]]
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.cvs.myapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.cvs.myapp-DG6fxWRjVXjsKQV_vwJwAw==/base.apk"],nativeLibraryDirectories=[/data/app/com.cvs.myapp-DG6fxWRjVXjsKQV_vwJwAw==/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2831)

It's just a new project with no other additions containing only a MainActivity class. Same new project will work if i rename the package to "com.demo.myapp".

Using Analyse APK, I can see that the classes.dex file doesn't contain the MainActivity. Is the name "cvs" causing the issue as it will work perfectly with any other name instead of it?

gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

build.gradle(project)

classpath 'com.android.tools.build:gradle:3.6.3'

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.cvs.myapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="com.cvs.myapp.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
vinv
  • 355
  • 2
  • 14
  • might be helpful https://stackoverflow.com/questions/22027219/proguard-seeming-to-remove-an-entire-packages-that-are-included-in-the-path – akashzincle Apr 23 '20 at 21:18
  • I don't believe it's a proguard issue as the same project will run perfectly if I rename the package name. It has got something to do with current the name I think. Also the same project will run on device if I change the gradle versions to classpath 'com.android.tools.build:gradle:3.0.1 distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip .It was working fine till I updated the versions to the latest. – vinv Apr 23 '20 at 21:50
  • did you add `multiDexEnabled true`? – IntelliJ Amiya Apr 24 '20 at 05:28
  • Yes, I had added. Didn't work. Even if i don't add add this and refactor the package name, it will run without any crash in device. – vinv Apr 24 '20 at 14:52
  • Looks like name "cvs" was being excluded according to link https://github.com/gradle/gradle/search?q=cvs&unscoped_q=cvs. Followed solution provided in link https://github.com/gradle/gradle/issues/11017. Added : org.apache.tools.ant.DirectoryScanner.removeDefaultExclude("**/CVS") org.apache.tools.ant.DirectoryScanner.removeDefaultExclude("**/CVS/**") to settings.gradle – vinv May 04 '20 at 15:33

1 Answers1

0

As you mentioned this is happening when you are using the latest Gradle that is currently 3.6.3, It has a new packaging tool ZipFlinger, which might be causing the issue, try below code to disable it

android.useNewApkCreator=false

Moreover I got some relevant links, please have a look.

https://issuetracker.google.com/issues/150198184

After upgrading to android 3.6.1 apk cant be installed on devices

Android App runtime crash after update gradle plugin 3.6

MultiDex problem with Android Studio 3.6 when implementing it the right way

akashzincle
  • 1,108
  • 6
  • 15
  • I had already tried this but the issue still persists. There is something else which is happening, I'm not sure. As i said, even without using the above code, my project will run on device with the latest gradle versions if I simply refactor the package name from "com.cvs.myapp" to "com.demo.myapp" or "com.sample.myapp". It's the word "cvs" which is causing the issue apparently. – vinv Apr 23 '20 at 22:18