Home » Android » android – ClassNotFoundException dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

android – ClassNotFoundException dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

Posted by: admin May 14, 2020 Leave a comment

Questions:

This error has come up a few times on Stackoverflow, I will reference to other questions in this question.

My project is an Android Application using the Android Maven Plugin to include libraries but also including some libraries locally as they are not provided via maven. My IDE is Eclipse. I have used this tutorial mostly to configure it. I am rather new to maven.

In short, I am unable to start the Application on my phone. When starting it I am presented with the above written Error concerning the Activity that is my start Activity called SubscriptionView. The entire error-trace below:

07-17 15:47:42.170: E/AndroidRuntime(20071): FATAL EXCEPTION: main
07-17 15:47:42.170: E/AndroidRuntime(20071): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.dynamixsspbridge/com.example.dynamixsspbridge.SubscriptionView}: java.lang.ClassNotFoundException: com.example.dynamixsspbridge.SubscriptionView
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.os.Looper.loop(Looper.java:137)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.app.ActivityThread.main(ActivityThread.java:4921)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at java.lang.reflect.Method.invokeNative(Native Method)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at java.lang.reflect.Method.invoke(Method.java:511)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at dalvik.system.NativeStart.main(Native Method)
07-17 15:47:42.170: E/AndroidRuntime(20071): Caused by: java.lang.ClassNotFoundException: com.example.dynamixsspbridge.SubscriptionView
07-17 15:47:42.170: E/AndroidRuntime(20071):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
07-17 15:47:42.170: E/AndroidRuntime(20071):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
07-17 15:47:42.170: E/AndroidRuntime(20071):    ... 11 more

Now, there are multiple solutions for this suggested:

  1. Checking if one does in fact export private Libraries by going to “”Build Path” -> “Configure Build Path…”. 2. In the “Order and Export” Tab, Make the “Android Private Libraries” option checked. Hoping to work.” I had that option checked, the error occured anyway.
  2. Make sure ProGuard does not strip classes away: As far as I know I do not use proguard. From what I glance one has to activly use ProGuard, its not just there… I did not. (It says “Having ProGuard run is completely optional” on the android site.) I have checked my project.properties and the proguard line there is commented out.
  3. Do not name the folder for your external libraries lib but libs. I have done so for my local libraries. The maven libraries ofcourse live wherever Maven puts them. Potentially I could take all these jars and put them from the maven repo into libs… then stop using maven. While this may work, it hardly presents a solution.
  4. Remove Double Libs from Build Path. This is more or less the same problem described in 3. Hoever the point here is, that “You can’t have different versions of a single library”. Some libraries are known to provide other libs so one might be in my local folder and be provided by one of the libs added via maven. I include two libraries locally, one is not public thus if one is provided it would be android-support-v4.jar. I have deletet the jar, cleaned the project and exported again, no changes.
  5. Suggestions have been made, that this is actually a Eclipse problem. Restarting supposedly might ba helpful so I did. To no avail. I have tried it with and without deleting bin and gen folder.
  6. Spelling errors
  7. Using the m2e Plugin (already doing that)

Other Ideas that did not pan out:

Java Version: On of the things I feel might be responsible si my use of Java 1.5. However, while 1.6 is recommended, 1.5 should work. Switching to 1.6 does not change anything either.

Libraries included via Maven are not exported/dexed: Another issue I see is that the Maven Dependnecies do not show up as dexed Libraries in the folder bin/dexedLibs. While I believe that this is going to be an issue at a later time I have removed all classes that use these libs from the project and the error remains.

The problem is clearly somehow related to using Maven. If I create a fresh project, everything works fine until I convert the project to a maven project and add the libraries via the pom.xml, even if I have no classes using any of the libraries.

EDIT Further investigation: By creating another new project and found that on the first “right clock->configure->convert to maven” nothing is imported even after I change the pom.xml. I then “disable maven nature” and then “convert to maven”. Now all the libraries are imported and now the error occurs. When I include the pom.xml into the project before converting the same error occurs.

Strangely enough, if I then “right click->maven->disable maven nature” and delete all the maven libs and files, the problem remains.

All this also happens with a fresh sample project (just the stanard activity and xml created by eclipse) after I convert to maven and the maven libs are in the project so it is apparently not related to my code at all…

The pom.xmllooks like this

    <project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>DynamixSSPBridge</groupId>
  <artifactId>DynamixSSPBridge</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>DynamixSSPBridge</name>
  <properties>
        <java-version>1.6</java-version>
  </properties>
  <repositories>
        <repository>
            <id>itm-maven-repository-releases-site</id>
            <url>https://maven.itm.uni-luebeck.de/content/repositories/releases/</url>
        </repository>
    </repositories> 
  <dependencies>
      <dependency>
               <groupId>com.google.android</groupId>
               <artifactId>android</artifactId>
               <version>2.3.3</version>
               <scope>provided</scope> 
        </dependency>
        <dependency>
            <groupId>de.uniluebeck.itm</groupId>
            <artifactId>ncoap</artifactId>
        <version>1.0.1</version>
    </dependency> 
 </dependencies>
 <build>
  <finalName>${project.artifactId}</finalName>
  <sourceDirectory>src</sourceDirectory>
  <pluginManagement>
   <plugins>
    <plugin>
     <groupId>com.jayway.maven.plugins.android.generation2</groupId>
     <artifactId>android-maven-plugin</artifactId>
     <version>3.1.1</version>
     <extensions>true</extensions>
    </plugin>
   </plugins>
  </pluginManagement>
  <plugins>
   <plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <configuration>
     <sdk>
      <platform>9</platform>
     </sdk>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>

Another Idea was to create a maven project with a specific android archetype as described here. However this does not seem to work as I always get an “Unable to create project from archetype” error (see picture). Creating a non android maven project was another bad try, since it isn’t an android project it does not resolve the R.x references and does not dex libraries…

Error message in eclipse

Any Ideas?

How to&Answers:

I’ve had same issue. I’d recommend you to depend on maven commands solely and not use IDE for anything (except for de-buging), because maven-android-plugin compiles stuff in its own way.

Installing local jar files

You can install local libraries jar files (which not available on-line for Maven) to your local repository:

For example, here we copy android.jar of 4.03 which is not available on-line, to local repository on our machine:

mvn install:install-file \
 -Dfile=$ANDROID_HOME/platforms/android-15/android.jar \
 -DgroupId=com.google.android \
 -DartifactId=android \
 -Dversion=4.0.3 \
 -Dpackaging=jar \
 -DgeneratePom=true

Now we can include it in POM:

  <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>${platform.version}</version>
        <scope>provided</scope>
  </dependency>

Maven will look in local repository and use these jar files.

Setting correct scope

The problem of classes not being included (in my case) was caused by wrong <scope> of dependencies in POM. So, for all library’s dependencies set <scope> to compile.

Try running mvn clean,mvn install, and mvn:android deploy.

Your Maven project is good only when you are able to run it from mvn command line without any IDE or so.