0

I am trying to compile using maven without success. Error: com.rhp.mobile.android E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable

What I am doing is referencing android app-compact-v7 lib project.

Here's the important part of the pom that I migh suspect is causing something:

DEPENDENCY:

<dependency>
<groupId>android.support</groupId>

<artifactId>compatibility-v7-appcompat</artifactId>

<version>19.0.1</version>
<type>apklib</type>
</dependency>

<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>19.0.1</version>
<type>jar</type>
</dependency>

COMPILER PLUGIN:

<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
<version>3.6.1</version>
<configuration>
<sdk>
<platform>17</platform>
</sdk>
<dex>
<jvmArguments>
<jvmArgument>-Xmx1024M</jvmArgument>
</jvmArguments>
</dex>
</configuration>
<!--<configuration>-->
<!--<resourceOverlayDirectory>${resourceOverlayDirectory}</resourceOverlayDirectory>-->
<!--</configuration>-->
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<!-- During release:perform, enable the "release" profile -->
<releaseProfiles>release</releaseProfiles>
</configuration>
</plugin>
</plugins>
</build>

Thanks!

cesarmax
  • 414
  • 1
  • 5
  • 12
  • possible duplicate of [How do I use android libraries (apklibs) with maven and eclipse?](http://stackoverflow.com/questions/11190932/how-do-i-use-android-libraries-apklibs-with-maven-and-eclipse) – Marcin Orlowski Apr 09 '14 at 15:54
  • i'm not trying to integrate it with eclipse. this is from command line that is failing... – cesarmax Apr 09 '14 at 17:50

1 Answers1

0

The config of Proguard is the problem!

CONTEXT: Application that is built using Maven and dependencies. We added a library (in our application) to implement a Slide Menu with ActionBar. Successfully implement a proof of concept on the menu. More info at: http://developer.android.com/design/patterns/navigation-drawer.html

PROBLEM We add the app compat v7 lib project to put the NavigationDrawer, configure the lib and apklib in maven. We generate the executable app "for development", everything went well. Works bookstore, we have no problem, we include the assets well and all is well.

The problem is when we create an apk RELEASE CANDIDATE to go to Google Play Store, which generates well, and when RUN THE APP, we throws the following error:

com.rhp.mobile.android E/AndroidRuntime? FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable

We use proguard into the maven steps.

THE SOLUTION:

a) missing dependencies for Maven? NO.

b) Am I missing something in the install Maven repository? No.

c) Proguard. That was the problem, the plugin and its settings.

What does ProGuard? in summary, ProGuard removes all unused APK our classes. With external libraries our project, as we only use part of the library, the classes detected not use and delete the resulting file, rather decreasing size of the application in certain cases. But this can sometimes generate that R references fail, and thus caused us our mistake.

Proguard works when we export the APK to RELEASE CANDIDATE, not when it's run in emulator / device. Basically because it would be impossible use the debug with obfuscated code.

Then, in our project we create the file proguard.conf these 4 lines at the end:

# # # # - Support Library v7 - 
-dontwarn android.support.v7. ** 
-keep class ** {* android.support.v7.; } 
-keep interface android.support.v7 ** {*.; }

With this we create the release candidate. Signed and lined up, ready to get on the Google Play Store.

Sorry if the comment was long explanation, but I found it helpful for you.