2

I am trying to use maven dependency management in my android project. I am using the below

I have a classes.jar package which i convert into a maven artifact using

mvn clean org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -DgroupId=com.example.test -DartifactId=test -Dversion=1.0 -DpomFile=pom.xml -Dpackaging=jar -Dfile=classes.jar  -DlocalRepositoryPath=test-maven-repo/releases/jar -DgeneratePom=true -DcreateChecksum=true

the included pom.xml which the above command refers to looks like this

<?xml version="1.0" encoding="UTF-8" ?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example.test</groupId>
  <artifactId>test</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>
  <dependencies>
     <dependency>
        <groupId>com.squareup.okhttp</groupId>
        <artifactId>okhttp</artifactId>
        <version>2.4.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.android.support</groupId>
        <artifactId>appcompat-v7</artifactId>
        <version>22.2.0</version>
        <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

Once i have the artifact deployed in my private local maven repo ( named test-maven-repo on my system), I create a new android project ( tested it to be running at this point on my android device) and convert it to maven

convert to maven

and create my POM file using enter image description here

this is where things start going wrong

Problem 1 Just as i click on Convert to Maven Project, build system fires up and i notice this in my console

R.Java was modified!
R.Java was modified!

When i try to run my app i get the below stacktrace in my logcat

07-08 10:58:12.998: E/AndroidRuntime(31032): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test_app_1/com.example.test_app_1.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.test_app_1.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.test_app_1-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.app.ActivityThread.access$900(ActivityThread.java:154)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.os.Handler.dispatchMessage(Handler.java:102)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.os.Looper.loop(Looper.java:135)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.app.ActivityThread.main(ActivityThread.java:5289)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at java.lang.reflect.Method.invoke(Native Method)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at java.lang.reflect.Method.invoke(Method.java:372)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
07-08 10:58:12.998: E/AndroidRuntime(31032): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.test_app_1.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.test_app_1-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
07-08 10:58:12.998: E/AndroidRuntime(31032):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
07-08 10:58:12.998: E/AndroidRuntime(31032):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
07-08 10:58:12.998: E/AndroidRuntime(31032):    ... 10 more
07-08 10:58:12.998: E/AndroidRuntime(31032):    Suppressed: java.lang.ClassNotFoundException: com.example.test_app_1.MainActivity
07-08 10:58:12.998: E/AndroidRuntime(31032):        at java.lang.Class.classForName(Native Method)
07-08 10:58:12.998: E/AndroidRuntime(31032):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
07-08 10:58:12.998: E/AndroidRuntime(31032):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
07-08 10:58:12.998: E/AndroidRuntime(31032):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
07-08 10:58:12.998: E/AndroidRuntime(31032):        ... 13 more
07-08 10:58:12.998: E/AndroidRuntime(31032):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

NOTE : I tested it to work with Eclipse Luna but after i guess i updated to android-m2e plugin v1.6 , problem 1 re-appeared.

Problem 2 With Eclipse Luna and android-m2e plugin v1.5 , my project worked , as in it would compile and run in my android device. But, this time only the maven artifact i reference is downloaded as a dependency , the transitive dependencies my artifact depends on (also referenced in its own pom.xml file) would not get downloaded on their own from my test repo.

my project's pom.xml looks like below ( where the repo is hosted on a server, link in the code)

<dependencies>
 <dependency>
    <groupId>com.example.test</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <scope>compile</scope>
 </dependency>
</dependencies>
<repositories>
 <repository>
    <id>company</id>
    <name>test-company-repo</name>
    <url>http://git.company.com/user/test-maven-repo/raw/master/releases/jar/</url>
 </repository>
</repositories>

i am only getting the test.jar under my maven dependencies section. There is no OkHttp.jar or okio.jar on which my test.jar depends ( which should have been pulled from the maven central transitively) NOTE1: I have tried adding maven central along with my private test-maven-repo.

NOTE2: Everything works like butter when i use maven repo in Android Studio with gradle.

Questions :

  • Is my setup wrong for using maven dependency management in android project for eclipse?
  • What am i doing wrong here?
  • Is the Maven version/m2e-android plugin/eclipse version or basically the combination of these three i use doing something with the execution of dependency management ?
Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
Nishant Srivastava
  • 4,723
  • 2
  • 24
  • 35
  • Any specific reason why you prefer Maven over Gradle? Just curious. – Egor Jul 08 '15 at 18:58
  • I did not say i prefer maven.As i mentioned in my question I work on android studio and use gradle, but as it is there are people who still use eclipse and maven. I have a library to be distributed via my own private maven repo. I have the whole process easy and working for gradle with 3 lines of code. But to get it to work for eclipse people , i am having trouble. – Nishant Srivastava Jul 08 '15 at 19:02

0 Answers0