DrawerLayout not found in Android Maven project at runtime

Ok, so I have been trying to figure out this issue for several weeks and have been on StackOverflow, looking heavily on similar issues and trying to apply them to my own situation to no avail. I'm worried, I'm just doing something incredibly stupid or forgetting something stupid and will be wasting time on someone, but at the moment I have no options or ideas, so I apologize if this happens. I am not using Eclipse or Android Studio, just the Maven CLI. I need to use DrawerLayout in my application, but the application crashes while trying to instantiate due to not being able to find the class (and presumably the rest of the support-v4 package) at runtime. So, step by step.

Here's the line of code that creates the DrawerLayout:

DrawerLayout drawer = new android.support.v4.widget.DrawerLayout(this);

      

Here is a stack trace of how the application crashes when trying to create a new instance of DrawerLayout.

E/AndroidRuntime( 2065): FATAL EXCEPTION: main
E/AndroidRuntime( 2065): Process: com.patron.main, PID: 2065
E/AndroidRuntime( 2065): java.lang.NoClassDefFoundError: android.support.v4.widget.DrawerLayout
E/AndroidRuntime( 2065):        at com.patron.main.FlashMenu.onCreate(FlashMenu.java:120)
E/AndroidRuntime( 2065):        at android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime( 2065):        at   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime( 2065):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
E/AndroidRuntime( 2065):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime( 2065):        at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime( 2065):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime( 2065):        at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 2065):        at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 2065):        at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 2065):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 2065):        at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 2065):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 2065):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
W/ActivityManager( 1228):   Force finishing activity com.patron.main/.FlashMenu

      

This is how I include the dependency in my POM.xml:

<dependency>
  <groupId>com.android.support</groupId>
  <artifactId>support-v4</artifactId>
  <version>21.0.3</version>
  <type>aar</type>
  <exclusions>
    <exclusion>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
    </exclusion>
  </exclusions>
</dependency>

      

I am using the local maven repository provided by google in the android-sdk / extras / android / m2repository folder as suggested by another SO post. Obviously it can compile and run fine, so I'm pretty sure that's correct. When I call the mvn: build-classpath dependency to see the compilation class path, it shows me this: Classpath

And then manually opening the AAR folder in 7zip and checking the jar classes to make sure the DrawerLayout is there, I can see that it is definitely there: DrawerLayout in Classpath

So, at this point I'm not sure what I can change or do to make this support package available at runtime. I went over the classpath in detail and I'm pretty sure I don't import the support-v4 package twice, just once, and judging by the nature of the errors when importing twice, I don't think I can compile if that was the problem. I tried to manually set up the dependency scope for compilation (which should be correct) and then at runtime and provided just in case with no luck. If anyone has any ideas as to what might be the problem to solve this NoClassDefFoundError it would be very helpful.

+3


source to share


1 answer


Found it out. For posterity: You need to update to the latest Android Maven Plugin to avoid this error. Also, an old bug I ran into where ActivityCompat21 was not found across several other classes that I fixed with a hacked workaround was also fixed by updating to version 4.0.0-rc2 of the plugin.



<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>4.0.0-rc.2</version>
    <extensions>true</extensions>
    <configuration>
        <includeLibsJarsFromAar>true</includeLibsJarsFromAar>
    </configuration>
</plugin>

      

0


source







All Articles