Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add meta includes from main jar artifact #602

Merged
merged 1 commit into from
Mar 14, 2015

Conversation

kedzie
Copy link
Contributor

@kedzie kedzie commented Mar 6, 2015

The META-INF includes functionality added back in stripped resources from the META-INF folder but only from 3rd party jar dependencies. Not resources from the actual application. So I added the output jar to the list of jars that are processed by the addMetaInf function to include application resources as well.

if ( this.apkMetaInf != null )
{
File outputJar = new File( outputApk.substring( 0, outputApk.length() - 3 ) + "jar" );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe using a property ${finalName}.jar for this value is betting than the substring thing.

@mosabua
Copy link
Member

mosabua commented Mar 6, 2015

The jar is just a side effect. Everything should go into the apk or aar directly. This seems wrong unless I am misunderstanding something. Wdyt @simpligility/android-maven-plugins-core-committers

@william-ferguson-au
Copy link
Contributor

I'm struggling to understand why there would be any jars added to the APK. AT that point all Java classes should be dexed.

Most definitely the project jar should not be included.

@mosabua
Copy link
Member

mosabua commented Mar 7, 2015

As far as I understand this is about the META-INF from the jar. Even so though I think this is wrong. To a wide degree the fact that there is a jar being produced by the Android Maven Plugin is a legacy thing since it needed to be there to get instrumentation tests and other things to work. But I certainly dont think we should make this a required thing for e.g. the META-INF usage. I am more inclinded to work towards NOT creating a jar anymore.

What is the use case for this @kedzie ?

@kedzie
Copy link
Contributor Author

kedzie commented Mar 7, 2015

so the android apk packaging tool strips contents of meta inf folder. the
include property puts meta resources back into the apk after packaging.
On Mar 6, 2015 7:00 PM, "Manfred Moser" [email protected] wrote:

As far as I understand this is about the META-INF from the jar. Even so
though I think this is wrong. To a wide degree the fact that there is a jar
being produced by the Android Maven Plugin is a legacy thing since it
needed to be there to get instrumentation tests and other things to work.
But I certainly dont think we should make this a required thing for e.g.
the META-INF usage. I am more inclinded to work towards NOT creating a jar
anymore.

What is the use case for this @kedzie https://github.com/kedzie ?


Reply to this email directly or view it on GitHub
#602 (comment)
.

@kedzie
Copy link
Contributor Author

kedzie commented Mar 7, 2015

now it loops through the dependencies and adds the meta inf resources to
the apk. but not from the apps resources. so i included the app jar into
the list of jars from which resources are copied. we could instead copy
them from the classes folder to not depend on that jar being there..
On Mar 7, 2015 5:06 PM, "Marek Kedzierski" [email protected]
wrote:

so the android apk packaging tool strips contents of meta inf folder. the
include property puts meta resources back into the apk after packaging.
On Mar 6, 2015 7:00 PM, "Manfred Moser" [email protected] wrote:

As far as I understand this is about the META-INF from the jar. Even so
though I think this is wrong. To a wide degree the fact that there is a jar
being produced by the Android Maven Plugin is a legacy thing since it
needed to be there to get instrumentation tests and other things to work.
But I certainly dont think we should make this a required thing for e.g.
the META-INF usage. I am more inclinded to work towards NOT creating a jar
anymore.

What is the use case for this @kedzie https://github.com/kedzie ?


Reply to this email directly or view it on GitHub
#602 (comment)
.

@kedzie
Copy link
Contributor Author

kedzie commented Mar 7, 2015

this is about required resources, like meta-inf/services files.. or
pom.properties.
On Mar 7, 2015 5:08 PM, "Marek Kedzierski" [email protected]
wrote:

now it loops through the dependencies and adds the meta inf resources to
the apk. but not from the apps resources. so i included the app jar into
the list of jars from which resources are copied. we could instead copy
them from the classes folder to not depend on that jar being there..
On Mar 7, 2015 5:06 PM, "Marek Kedzierski" [email protected]
wrote:

so the android apk packaging tool strips contents of meta inf folder. the
include property puts meta resources back into the apk after packaging.
On Mar 6, 2015 7:00 PM, "Manfred Moser" [email protected] wrote:

As far as I understand this is about the META-INF from the jar. Even so
though I think this is wrong. To a wide degree the fact that there is a jar
being produced by the Android Maven Plugin is a legacy thing since it
needed to be there to get instrumentation tests and other things to work.
But I certainly dont think we should make this a required thing for e.g.
the META-INF usage. I am more inclinded to work towards NOT creating a jar
anymore.

What is the use case for this @kedzie https://github.com/kedzie ?


Reply to this email directly or view it on GitHub
#602 (comment)
.

@kedzie
Copy link
Contributor Author

kedzie commented Mar 9, 2015

In summary, if you don't like depending on the main artifact jar being there, we could potentially change the code to copy the META-INF resources from the ${outputDirectory}/META-INF instead. But then we would also need to get the pom.xml and pom.properties into the apk. Using the jar is just a far simpler change, which is why I did it this way initially.

This change is required for the Drools Android work I'm doing. There are a lot of important resources in the META-INF folder in drools projects. I imagine other projects as well...

@william-ferguson-au
Copy link
Contributor

It's not about not liking the main artifact jar being there. Copying the main jar to your APK should have zero effect. The Android runtime won't open your jar and read any contained resources such as META-INF/services.

Let me restate your problem so I understand.

  • Your Android app makes use of the java services mechanism in some respect.
  • So it needs to load resources from META-INF/services
  • You need to get your resources into the APK in that location.

I am pretty sure that standard java resources (src/main/resources) are copied to the APK. If that's the case then I'm not sure why this isn't working for you.

@kedzie
Copy link
Contributor Author

kedzie commented Mar 12, 2015

Your understanding of my problem is correct. But you aren't understanding the current behavior of the plugin.

files under src/main/resources/META-INF are NOT copied into the apk.

The android packaging tool strips the contents of the META-INF folder. That is why this android-maven-plugin has the feature to add resources back into the APK after it is packaged. That functionality is controlled using the apk->metaInf include/exclude plugin configuration properties.

<apk>
                        <metaInf>
                            <includes>
                                <include>services/**</include>
                                <include>kmodule.*</include>
                                <include>HelloKB/**</include>
                                <include>drools**</include>
                                <include>maven/${project.groupId}/${project.artifactId}/**</include>
                            </includes>
                        </metaInf>
                    </apk>

The problem with that functionality is that it only copies back in META-INF resources from the dependencies, NOT from the artifact itself. So if you put some resources into src/main/resources/META-INF/ they will not be in the output APK. However they are in the jar artifact packaged by the normal maven-jar-plugin. This includes the pom.properties and pom.xml files. My change modifies the existing functionality, which adds the stripped META-INF resources back into the apk, to also include resources from the project.

@kedzie
Copy link
Contributor Author

kedzie commented Mar 12, 2015

And to clarify I am not packaging the jar file into the apk. It is copying the META-INF resources from the jar file and adding them to the APK. This is done to replace the META-INF resources which were stripped by the apk packaging tool.

@kedzie
Copy link
Contributor Author

kedzie commented Mar 12, 2015

Take a look at any APK created by the android-maven-plugin, notice it doesn't have maven/groupId/artifactId/pom.properties or maven/groupId/artifactId/pom.xml files. Both of which I need.

@kedzie
Copy link
Contributor Author

kedzie commented Mar 13, 2015

Could you please chime in on this @mosabua? I'm confident this is a valid change but seems I'm failing to get the point across. I could provide an example project for instance..

william-ferguson-au added a commit that referenced this pull request Mar 14, 2015
Add meta includes from main jar artifact
@william-ferguson-au william-ferguson-au merged commit 525678f into simpligility:master Mar 14, 2015
@william-ferguson-au
Copy link
Contributor

Thanks @kedzie I understand what you were after now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants