Duplicate file when deploying apk

2019-04-10 01:55发布

问题:

This problem seems to come up for a few people, but I haven't been able to apply the solution suggested in other threads for one reason or another so...

I am trying to build a simple android app with an embedded webserver. The server of choice if jetty. I am using maven to manage dependencies with the maven-android-plugin. I have added jetty-server v8.x as a dependency with the default scope. When I try and deploy my apk to the sandbox I get an error

Found duplicate file for APK: about.html

So the file in question is from the jetty package, or rather it is found in two jetty packages, one being a dependency of jetty-server. Other threads out there seem to be suggest I delete the file from one jar or the other but this is not really a scalable solution as I am not the owner of the jars.

Is there a more general solution to this problem? Something that manages the conflict and build or deploy time?

I should note, I am a bit of a Java noob, and have gone the NetBeans and maven route because this is the toolkit I'm familiar with.

回答1:

OK, found it. The solution is to build using the following command

mvn android:deploy -Dandroid.extractDuplicates=true


回答2:

There are a couple of issues:

First, to integrate Jetty, your project is going to need a pom.xml file. The Android APK (as-is) does not know how to resolve a pom with Maven dependencies without some sort of bridge. So, you'll need to install a few plugins for Pom management onto Eclipse. Follow the instructions here: http://rgladwell.github.com/m2e-android/ (I found it easier to create a new project using the method described here rather than converting my existing Android app to a Maven project, but I'm sure it'll work either way.)

Second, once you've installed this, you're going to have to make sure your pom.xml contains the necessary dependencies, build goals, and variables. So, open up your pom.xml, and make sure you have the following:

  1. In the "build" node:

    sourceDirectory -> src

    defaultGoal -> install (I suppose...)

  2. In the "dependencies" node:

    ... all the jetty/cometd dependencies (org.cometd.java, org.eclipse.jetty, etc.)

Third, you should know that you can't just click the green run button and launch the app via ADB. You have to install it the maven way (Run As -> Maven build/install/test/whatever)



回答3:

You should open up your war file and check if you actually have two about.html files in there. Some time ago I had two web.xmls in my war files. If you actually have duplicates then you should try to exclude those files.

Maybe you have one file in your project and the duplicate is generated by the maven plugin.



回答4:

I also just realized that you're probably already properly using the android-maven plugin. One other important tip: change the scope to runtime on the jetty dependencies. This builds successfully for me, whereas using the default scope (compile) always threw the duplicate file in APK error.