Android project does not start on device when support library is included in pom.xml file
I am having trouble getting my current Android project running on my device. the project is built without erros (with maven), but when running this error happens:
E/AndroidRuntime(12097): FATAL EXCEPTION: main
E/AndroidRuntime(12097): Process: org.hello, PID: 12097
E/AndroidRuntime(12097): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.hello/org.hello.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "org.hello.MainActivity" on path: DexPathList[[zip file "/data/app/org.hello-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.hello-1, /vendor/lib, /system/lib]]
E/AndroidRuntime(12097): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2124)
E/AndroidRuntime(12097): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
E/AndroidRuntime(12097): at android.app.ActivityThread.access$800(ActivityThread.java:139)
E/AndroidRuntime(12097): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
E/AndroidRuntime(12097): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(12097): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(12097): at android.app.ActivityThread.main(ActivityThread.java:5086)
E/AndroidRuntime(12097): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(12097): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(12097): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime(12097): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime(12097): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(12097): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.hello.MainActivity" on path: DexPathList[[zip file "/data/app/org.hello-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.hello-1, /vendor/lib, /system/lib]]
E/AndroidRuntime(12097): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(12097): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
E/AndroidRuntime(12097): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
E/AndroidRuntime(12097): at android.app.Instrumentation.newActivity(Instrumentation.java:1084)
E/AndroidRuntime(12097): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
E/AndroidRuntime(12097): ... 11 more
W/ActivityManager( 916): Force finishing activity org.hello/.MainActivity
My MainActivity class:
package org.hello;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
public class MainActivity extends FragmentActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab1"), Tab1Fragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab2"), Tab2Fragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab3"), Tab3Fragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab4").setIndicator("Tab4"), Tab4Fragment.class, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void openSearch() {
//
}
public void openSettings() {
//
}
}
my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hello</groupId>
<artifactId>basic-tabs</artifactId>
<version>0.1.0</version>
<packaging>apk</packaging>
<properties>
<!-- use UTF-8 for everything -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<android.sdk.path>/home/kleber/android-sdk-linux/</android.sdk.path>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>20.0.0</version>
<scope>system</scope>
<systemPath>/home/kleber/android-sdk-linux/extras/android/support/v4/android-support-v4.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.9.0-rc.1</version>
<configuration>
<sdk>
<platform>19</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<executable>/home/kleber/jdk1.7.0_55/bin/javac</executable>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
the MainActivity class is placed in the correct directory inside my project (just like other projects that run without issue).
If I remove the dependency support-v4
(and all references in my code for a class from that library), I have no problem running this project.
Can anyone see what I am not seeing here?
ps .: the project with the problem is as follows: https://github.com/klebermo/basic_tab2
source to share
I can't remember correctly, but I had the same error using this support-library-v4 and I didn't even use Maven. But since you are really in desperate need of help here is the idea that I think it fixed my problem. If you have Eclipse (I don't know any other IDEs), go to the build path and go to Order and Export and uninstall or install Export in Support Library-v4.
source to share