pombreda / maven-android-plugin

Automatically exported from code.google.com/p/maven-android-plugin
0 stars 0 forks source link

Support for library projects #96

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm unable to get maven-android-plugin to work with library projects: 
http://developer.android.com/guide/developing/eclipse-adt.html#libraryProject

Does maven-android-plugin need specific support do get it working?

Original issue reported on code.google.com by henrik.a...@gmail.com on 21 Oct 2010 at 11:27

GoogleCodeExporter commented 9 years ago
I noticed an interesting comment concerning aidl files and library projects in 
the Android licencing project.

// Android library projects do not yet support AIDL, so this has been
// precompiled into the src directory.

Not sure why they are not supported.

I added apklib aidl file support. I don't have any projects to test against 
however. Can you give it a try and let me know how it goes?

Thanks

Original comment by nmaior...@gmail.com on 10 Dec 2010 at 12:40

GoogleCodeExporter commented 9 years ago
I think I might know what is causing the asset issue. This might be a tough one 
since the tool only supports providing 1 asset directory. Currently it's 
probably taking the apklib since it is stated last on the chain.

I need to put some thought in how to handle assets. Any ideas?

Original comment by nmaior...@gmail.com on 10 Dec 2010 at 12:42

GoogleCodeExporter commented 9 years ago
nmaiorana: Support for aidl's in library projects was added in ADT version 
0.9.8.   Maybe the Android licencing project just haven't updated their code 
yet?

I pulled the latest from the "issue-96-library-projects" branch.  Aidl's are 
still not compiled.

Original comment by henrik.a...@gmail.com on 10 Dec 2010 at 12:54

GoogleCodeExporter commented 9 years ago
I see that the original plug-in code attempts to put all the generated java 
files from AIDL in the generated-sources/aidl directory. For library projects 
I'm thinking they should go into the java directory of the library project's 
generated source directory.  Thoughts?

Original comment by nmaior...@gmail.com on 10 Dec 2010 at 9:57

GoogleCodeExporter commented 9 years ago
Looks like the Eclipse plug-in puts them in the gen directory right next to the 
R.java files. Looks like a good place to me.

Original comment by nmaior...@gmail.com on 10 Dec 2010 at 10:08

GoogleCodeExporter commented 9 years ago
Hello, 

I still think that there is something not working properly. 

I have created two projects (library + project that is using it) and it is not 
working for me. 

It throws following

E/AndroidRuntime(  308): java.lang.RuntimeException: Unable to start activity 
ComponentInfo{maven.tests/maven.tests.Main}: android.content.res.Reso
es$NotFoundException: File res/drawable/icon.png from xml type layout resource 
ID #0x7f020000
E/AndroidRuntime(  308):        at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(  308):        at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(  308):        at 
android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(  308):        at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(  308):        at 
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  308):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  308):        at 
android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  308):        at java.lang.reflect.Method.invokeNative(Native 
Method)
E/AndroidRuntime(  308):        at 
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  308):        at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  308):        at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  308):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  308): Caused by: 
android.content.res.Resources$NotFoundException: File res/drawable/icon.png 
from xml type layout resource ID #0
020000
E/AndroidRuntime(  308):        at 
android.content.res.Resources.loadXmlResourceParser(Resources.java:1916)
E/AndroidRuntime(  308):        at 
android.content.res.Resources.loadXmlResourceParser(Resources.java:1871)
E/AndroidRuntime(  308):        at 
android.content.res.Resources.getLayout(Resources.java:731)
E/AndroidRuntime(  308):        at 
android.view.LayoutInflater.inflate(LayoutInflater.java:318)
E/AndroidRuntime(  308):        at 
android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime(  308):        at 
maventests.MyUtils.showLayoutInDialog(MyUtils.java:14)
E/AndroidRuntime(  308):        at maven.tests.Main.onCreate(Main.java:11)
E/AndroidRuntime(  308):        at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  308):        at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(  308):        ... 11 more
E/AndroidRuntime(  308): Caused by: java.io.FileNotFoundException: Corrupt XML 
binary file
E/AndroidRuntime(  308):        at 
android.content.res.AssetManager.openXmlAssetNative(Native Method)
E/AndroidRuntime(  308):        at 
android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:485)
E/AndroidRuntime(  308):        at 
android.content.res.Resources.loadXmlResourceParser(Resources.java:1898)
E/AndroidRuntime(  308):        ... 19 more
W/ActivityManager(   59):   Force finishing activity maven.tests/.Main

Thanks in advance to look at it.

Tom

Original comment by tom.huba...@gmail.com on 11 Dec 2010 at 9:00

Attachments:

GoogleCodeExporter commented 9 years ago
Hello, I was playing with my sample projects, I found one issue in POM.XML but 
I still believe that resources included in library project are not handle 
properly. Adding latest version of sample project.

Thanks for your effort on Maven Android Plugin.

Tom

Original comment by tom.huba...@gmail.com on 12 Dec 2010 at 6:37

Attachments:

GoogleCodeExporter commented 9 years ago
I have updated the branch with the latest. Should handle assets properly and 
now works with AIDL files. The aidl files should be in your source directory.

https://github.com/nmaiorana/maven-android-plugin/tree/issue-96-library-projects

Tom, I noticed in your library project that you have the packaging type as 
"apk". This should be "apklib". Let me know if that helps.

Original comment by nmaior...@gmail.com on 12 Dec 2010 at 10:47

GoogleCodeExporter commented 9 years ago
it's working! great, thanks!

Original comment by croon...@googlemail.com on 13 Dec 2010 at 9:06

GoogleCodeExporter commented 9 years ago
I get this error when I tried the latest plugin:

[ERROR] 
/Users/me/src/myproject/no/target/generated-sources/gen/com/myproject/R.java:[10
,13] duplicate class: com.aspiro.wamp.R

Original comment by henrik.a...@gmail.com on 13 Dec 2010 at 11:16

GoogleCodeExporter commented 9 years ago
Your library project probably has the same package name as your main project. 
Try giving it a different package name.

Original comment by nmaior...@gmail.com on 13 Dec 2010 at 12:13

GoogleCodeExporter commented 9 years ago
The Eclipse SDK allows equal package names.  Shouldn't maven-android-plugin do 
that as well?

Original comment by henrik.a...@gmail.com on 13 Dec 2010 at 12:17

GoogleCodeExporter commented 9 years ago
For the android manifest package? 

Original comment by nmaior...@gmail.com on 13 Dec 2010 at 4:00

GoogleCodeExporter commented 9 years ago
Yup

Original comment by henrik.a...@gmail.com on 13 Dec 2010 at 6:34

GoogleCodeExporter commented 9 years ago
I know what the problem is. The original plugin puts the R.java files in the 
target/generates-sources/r directory (android.genDirectory) and the apklib want 
to put them in the target/generates-sources/gen directory.  For a work around, 
try setting 
android.genDirectory=${project.build.directory}/generated-sources/gen for the 
plug-in in the pom file.

I'll get a more permanent solution soon.

Original comment by nmaior...@gmail.com on 13 Dec 2010 at 7:12

GoogleCodeExporter commented 9 years ago
@nmaiorana

When I setup <packaging>apklib</packaging> (in the header of the pom.xml not in 
plugin configuration, then it says

The project maven-tests:library-project:1.0.1 
(C:\Users\Tom\workspace\experiments\maven-tests\library-project\pom.xml) has 1 
error
  Unknown packaging: apklib @ line 8, column 16

I'm using plugin of version 2.8.3. Is it a root cause? Should I use some 
unstable one from GIT?

Thanks a lot 
Tom

Original comment by tom.huba...@gmail.com on 13 Dec 2010 at 7:32

GoogleCodeExporter commented 9 years ago
tom.hubalek: See 
http://code.google.com/p/maven-android-plugin/issues/detail?id=96#c45

Original comment by henrik.a...@gmail.com on 13 Dec 2010 at 7:36

GoogleCodeExporter commented 9 years ago
Oh, I'm sorry, I overlooked it.

Original comment by tom.huba...@gmail.com on 13 Dec 2010 at 7:40

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Henrik, my last comment probably was not clear.

Try this setting for the plugin:
<configuration>
...                                 
<genDirectory>${project.build.directory}/generated-sources/gen</genDirectory>
...

Original comment by nmaior...@gmail.com on 14 Dec 2010 at 2:12

GoogleCodeExporter commented 9 years ago
nmaiorana: Thanks, you were pretty clear, I just wasn't near my source code :)

You were right, the duplicate R.java error disappeared when I added 
genDirectory to the apk (not apklib) project.  I still have to copy my 
properties files with an ant task, though.

Original comment by henrik.a...@gmail.com on 14 Dec 2010 at 7:46

GoogleCodeExporter commented 9 years ago
Cool. So src/main/resources are not being copied?

Original comment by nmaior...@gmail.com on 14 Dec 2010 at 1:00

GoogleCodeExporter commented 9 years ago
I have <sourceDirectory>src</sourceDirectory>, and I've got a property file in 
src/blaba.properties together with my java files.  (I know, not the most 
standard layout.)

Original comment by henrik.a...@gmail.com on 14 Dec 2010 at 2:02

GoogleCodeExporter commented 9 years ago
I want to provide the common stuff (apklib project) to a shared repository on 
our network. Im going to use mvn deploy:deploy-file to upload it to Nexus, but 
there are 4 generated files in the target folder to choose among:
- AndroidLibrary-1.0.0-SNAPSHOT.ap_
- AndroidLibrary-1.0.0-SNAPSHOT.apklib
- AndroidLibrary-1.0.0-SNAPSHOT.apksources
- AndroidLibrary-1.0.0-SNAPSHOT.jar

Whats the difference between these?

Original comment by croon...@googlemail.com on 21 Dec 2010 at 3:40

GoogleCodeExporter commented 9 years ago
apksource and apklibs are different artifact types. If you are trying to 
generate a android library type, apklib is what you want to deploy to Nexus. 

Original comment by nmaior...@gmail.com on 22 Dec 2010 at 12:45

GoogleCodeExporter commented 9 years ago
Nice this apklib branch but when will it be included in main project ? Tell me 
if i'm wrong but the apklib contains the same thing as apksources with manifest.

Original comment by jerome...@gmail.com on 23 Dec 2010 at 4:59

GoogleCodeExporter commented 9 years ago
Any estimation on when we can see this officially released?

Original comment by armond...@gmail.com on 23 Dec 2010 at 6:03

GoogleCodeExporter commented 9 years ago
Yes, it contains the same as the apksources, but during build time they are 
both treated differently. apklib types are used similar to the way Eclipse 
treats them.

Original comment by nmaior...@gmail.com on 24 Dec 2010 at 3:10

GoogleCodeExporter commented 9 years ago
Got the branched version from nmaiorana compiled and basically working (can 
launch an activity from a apklib). The only problem is that when I only define 
that activity in the android manifest file of the library the app cannot launch 
it (at the moment I added the activity to the applications manifest file). Do I 
need to start that activity in a special way from my app? I can see that the 
manifest from the lib has been extracted into the target folder of the app but 
is it "joined" with the app's? Unfortunately I cannot open the android manifest 
from the generated apk or ap_ files anymore (seems to be processed in some way, 
only binary stuff in there)...

Any ideas or hints would be highly appreciated!

Original comment by markus.korbel@gmail.com on 13 Jan 2011 at 11:45

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Does it support apklib dependencies for projects with apklib packaging? In 
other words, can library depend on library? Eclipse and Idea provide it.

Original comment by aleksand...@gmail.com on 31 Jan 2011 at 1:34

GoogleCodeExporter commented 9 years ago
when could we use apklib packages in the version from mvn repository? thanks!

Original comment by and....@gmail.com on 31 Jan 2011 at 1:42

GoogleCodeExporter commented 9 years ago
nmaiorana, thanks for your work on this so far.

Should my main (apk) application, which has a dependency of type apklib, 
compile in Eclipse? Put another way, I have m2eclipse installed and dependency 
resolution turned on for my main project, but in Eclipse, using the latest ADT, 
it can't see the classes in the apklib project. Running maven from the command 
line on the main project works fine, however, and the app compiles and deploys 
fine, pulling in the apklib as expected.

Which Eclipse plug ins do you have installed to make this work for you?

Original comment by outofcof...@gmail.com on 4 Feb 2011 at 3:36

GoogleCodeExporter commented 9 years ago
Your welcome. 

I use m2eclipse, but I never could get dependency resolution working so I just 
left it off. The main problem is that the ADK puts all the library source 
references in the project and you end up with class conflicts (if I recall 
properly). 

The main reason I wanted to get apklibs working with my android projects was to 
be able to apply the code obfuscation plug ins. So in eclipse I used the AKK 
without maven dependency management, but ran build using the maven package from 
m2eclipse.

I hope this helps.

Original comment by nmaior...@gmail.com on 4 Feb 2011 at 3:50

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi nmaior!
I am really interesting for tour fork of this plugin tio integrate library.
I check out your fork from 
https://github.com/nmaiorana/maven-android-plugin/tree/issue-96-library-projects
and when i do mvn install on this i get error...

Results :

Tests in error: 
  givenToolAaptAndPlatform1dot1ThenPathIsPlatformTools(com.jayway.maven.plugins.android.AndroidSdkTest)
  validPlatformsAndApiLevels(com.jayway.maven.plugins.android.AndroidSdkTest)

Original comment by sylvain....@backelite.com on 16 Feb 2011 at 11:38

GoogleCodeExporter commented 9 years ago
mvn -Dmaven.test.skip clean install

Original comment by and....@gmail.com on 16 Feb 2011 at 11:44

GoogleCodeExporter commented 9 years ago
The original test failed for me a well. Since I was only focusing in maven lib 
projects I did not fix the code for those tests. Run the install and skip the 
tests.

Original comment by nmaior...@gmail.com on 17 Feb 2011 at 12:21

GoogleCodeExporter commented 9 years ago
As I remeber this test checks whether you have all Android SDK versions in 
ANDROID_HOME. I didn't want to download all versions then added @Ignore to test.

By the way I want to tell you  about my mistakes with configuration. 

- Missing <type>apklib</type> in main project dependency to library project.
- Different versions of maven-android-project plugin in pom.xml. In main 
project master branch, in library project issue-96 branch.

With such configuration I didn't get any error during build but library project 
classes were missing in the application. That caused application crash during 
runtime.
I think that will save lot of time for developers like me not familiar with 
maven.

Original comment by pawzi...@gmail.com on 17 Feb 2011 at 8:38

GoogleCodeExporter commented 9 years ago
I've a problem using the branch of nmaior. Can anybody check and tell me what 
is the problem and if it's easy to solve.

http://stackoverflow.com/questions/5080117/no-resource-found-in-android-project-
using-a-library-project

Thank you

Original comment by ju...@frogtek.org on 22 Feb 2011 at 3:31

GoogleCodeExporter commented 9 years ago
I looked at the link. Is maxPoints defined in the lib project?

One think you can check is to see if it exists in the R directory under 
generated-sources.

Original comment by nmaior...@gmail.com on 23 Feb 2011 at 12:01

GoogleCodeExporter commented 9 years ago
No, the maxPoints is not defined in the lib project is defined in the main one.

Yes it appears in the R.java file inside generated-sources.

        public static final int maxPoints=0x7f010007;

Thank you very much for your time nmaior.

Original comment by ju...@frogtek.org on 23 Feb 2011 at 7:55

GoogleCodeExporter commented 9 years ago
Relevant to this issue. See the last (as of now anyway) post here:

http://groups.google.com/group/maven-android-developers/browse_thread/thread/d9b
f9f996d4c7ca2

Thanks,
Hugo

Original comment by h...@josefson.org on 25 Feb 2011 at 7:10

GoogleCodeExporter commented 9 years ago
Your branch doesn't solved my problem Hugo, thanks anyway.

I will try to solve it and made a pull request to the repository.

Original comment by ju...@frogtek.org on 1 Mar 2011 at 2:24

GoogleCodeExporter commented 9 years ago
Nick Maiorana's and Eric Bowman's code has now been merged into master, and 
released as maven-android-plugin 2.9.0-beta-1! Thank you so much for the code 
Nick, and Eric for the extra fixes. Especially, thank you all for your patience.

This beta release can be used just like any other release on Maven Central, 
without compiling maven-android-plugin from source.

In the maven-android-plugin-samples branch named 'beta', there are also some 
new samples which use the beta version of the plugin:
https://github.com/jayway/maven-android-plugin-samples/tree/beta/libraryprojects

I think I have tested all library project functionality, except aidl.

One important change I made compared to Nick's code: Java source code inside 
the .apklib file is now stored and fetched from the directory "src/" instead of 
"src/main/java/". This is to be compatible with non-Maven developers' library 
projects, which I think is of utter importance to grow the community. It means 
we can take any Android library project zip file and do 'mvn 
install:install-file ...' on it and simply start using it as a dependency. For 
those of you who have compiled the plugin from source before, and started to 
use the apklib functionality in any unreleased version of maven-android-plugin, 
you need to do 'mvn install' in all your apklib projects, so the .apklib files 
are rebuilt and installed into your ~/.m2/repository.

I will update the Changelog with this information and send out an announcement 
to the Maven Android Developers mailinglist with a call for testing.

With this I consider Issue 96 Fixed. For any issues you find with the beta 
release, please file separate Issues and include which beta version you are 
using.

Thanks,
Hugo

Original comment by h...@josefson.org on 5 Mar 2011 at 5:40

GoogleCodeExporter commented 9 years ago
"One important change I made compared to Nick's code: Java source code inside 
the .apklib file is now stored and fetched from the directory "src/" instead of 
"src/main/java/""

Wait, does this mean we can no longer use src/test/java for our testcases?

Original comment by mbur...@gmail.com on 7 Mar 2011 at 5:37

GoogleCodeExporter commented 9 years ago
“One important change I made compared to Nick's code: Java source code inside 
the .apklib file is now stored and fetched from the directory "src/" instead of 
"src/main/java/".”

I have to say I am not all that happy about as I use Maven directory layout. 
And I use "src/test" as well. And "src/setup" and "src/main/scripts" and 
"src/main/resources".

Original comment by Martin.K...@gmail.com on 17 Mar 2011 at 7:47

GoogleCodeExporter commented 9 years ago
Hi Michael and Martin! Sorry, I wasn't clear about that.

Yes, of course you should still use the default Maven directory layout in your 
project, with src/main/java and src/test/java. You can use any other directory 
layout too, including the awkward src/ one if you like, as long as you specify 
it in your pom.

The directory layout with the src/ directory, only applies inside the apklib 
file. The plugin will detect automatically where your sources are in your 
project according to your pom.xml configuration, and repackage relevant sources 
into the apklib file. Note that test sources are not included in the apklib 
file, just as they are not included in a jar.

Thanks,
Hugo

Original comment by h...@josefson.org on 20 Mar 2011 at 10:32

GoogleCodeExporter commented 9 years ago
Hugo, I just want to thank you and your team for laying down such a good 
foundation to move Android software development direction.

Original comment by nmaior...@gmail.com on 21 Mar 2011 at 11:58

GoogleCodeExporter commented 9 years ago
Thank you Nick for your kind words. You are now in a major way part of this 
with your contributions!

Original comment by h...@josefson.org on 22 Mar 2011 at 6:46