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

Error generating BuildConfig with transitive AAR dependency without classes.jar #640

Open
jpcarlino opened this issue Jun 10, 2015 · 14 comments

Comments

@jpcarlino
Copy link

Hello, i'm experiencing the following issue compiling my project using the latest android-maven-plugin 4.2.1. However it happens when com.google.android.gms:play-services:7.5.0 is a transitive dependency, not a direct one.

My relevant dependency chain is as follows:

com.google.android.gms:play-services:7.5.0 (aar) <- myGroupId:coreProject (aar) <- myGroupId:appProject

coreProject depends on play-services, while appProject depends on coreProject. However coreProject builds fine while appProject fails with this error:

[INFO] --- android-maven-plugin:4.2.1:generate-sources (default-generate-sources) @ appProject ---
[INFO] Manifest copied from appProject/AndroidManifest.xml to appProject/target/AndroidManifest.xml
[INFO] Extracting libs
[INFO] Extracting aar play-services...
[INFO] Extracting aar play-services-ads...
[INFO] Extracting aar play-services-analytics...
[INFO] Extracting aar play-services-appindexing...
[INFO] Extracting aar play-services-appinvite...
[INFO] Extracting aar play-services-appstate...
[INFO] Extracting aar play-services-base...
[INFO] Extracting aar support-v4...
[INFO] Extracting aar play-services-cast...
[INFO] Extracting aar mediarouter-v7...
[INFO] Extracting aar appcompat-v7...
[INFO] Extracting aar play-services-drive...
[INFO] Extracting aar play-services-fitness...
[INFO] Extracting aar play-services-games...
[INFO] Extracting aar play-services-gcm...
[INFO] Extracting aar play-services-identity...
[INFO] Extracting aar play-services-location...
[INFO] Extracting aar play-services-maps...
[INFO] Extracting aar play-services-nearby...
[INFO] Extracting aar play-services-panorama...
[INFO] Extracting aar play-services-plus...
[INFO] Extracting aar play-services-safetynet...
[INFO] Extracting aar play-services-wallet...
[INFO] Extracting aar play-services-wearable...
[INFO] Extracting aar coreProject...
[INFO] Generating R file for myGroupId:appProject:apk:3.0.0-SNAPSHOT
[INFO]     (skipping file '.gitattributes' due to ANDROID_AAPT_IGNORE pattern '.*')
[INFO] Generating R file for aar : com.google.android.gms.wearable
[INFO] Generating R file for aar : com.google.android.gms.plus
[INFO] Generating R file for aar : com.google.android.gms.location
[INFO] Generating R file for aar : myGroupId
[INFO] Generating R file for aar : com.google.android.gms.games
[INFO] Generating R file for aar : com.google.android.gms.analytics
[INFO] Generating R file for aar : com.google.android.gms.cast
[INFO] Generating R file for aar : com.google.android.gms.wallet
[INFO] Generating R file for aar : com.google.android.gms.appstate
[INFO] Generating R file for aar : com.google.android.gms.safetynet
[INFO] Generating R file for aar : com.google.android.gms.drive
[INFO] Generating R file for aar : com.google.android.gms.appindexing
[INFO] Generating R file for aar : com.google.android.gms.panorama
[INFO] Generating R file for aar : com.google.android.gms.all
[INFO] Generating R file for aar : com.google.android.gms.ads
[INFO] Generating R file for aar : com.google.android.gms.appinvite
[INFO] Generating R file for aar : com.google.android.gms.fitness
[INFO] Generating R file for aar : com.google.android.gms.identity
[INFO] Generating R file for aar : com.google.android.gms.gcm
[INFO] Generating R file for aar : com.google.android.gms.maps
[INFO] Generating R file for aar : com.google.android.gms
[INFO] Generating R file for aar : android.support.v7.mediarouter
[INFO] Generating R file for aar : com.google.android.gms.nearby
[INFO] Generating R file for aar : android.support.v7.appcompat
[INFO] Adding R gen folder to compile classpath: appProject/target/generated-sources/r
[ERROR] Error generating BuildConfig 
java.io.FileNotFoundException: appProject/target/unpacked-libs/cgag_play-services_7.5.0/classes.jar (No such file or directory)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:215)
    at java.util.zip.ZipFile.<init>(ZipFile.java:145)
    at java.util.jar.JarFile.<init>(JarFile.java:154)
    at java.util.jar.JarFile.<init>(JarFile.java:118)
    at com.simpligility.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.isBuildConfigPresent(GenerateSourcesMojo.java:1198)
    at com.simpligility.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.skipBuildConfigGeneration(GenerateSourcesMojo.java:1156)
    at com.simpligility.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateBuildConfig(GenerateSourcesMojo.java:1137)
    at com.simpligility.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.execute(GenerateSourcesMojo.java:329)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

As the error message suggests, i've verified that no classes.jar is found on appProject/target/unpacked-libs/cgag_play-services_7.5.0/ folder.

I saw that similar issues were addressed on #618 and #626 (when .aar doesn't contain a classes.jar file), however both are closed. By the way, i use this project layout since a year ago. Problems arised when i tried to include play-services:7.5.0 to my core project (which in turn forced me to upgrade from android-maven-plugin 3.9.0-rc.3 to 4.2.1).

@william-ferguson-au
Copy link
Contributor

Hmm looks like an edge case that hasn't been well covered yet.
Can you create a cut down pair of projects that I can spin up and test across.

@dessalines
Copy link

I too have trouble getting com.google.android.gms:play-services-cast:7.8.0 converted to a maven dependency. I downloaded it in the android SDK manager, and have successfully added others such as the support aars, but can't get play-services or play-services-cast to work.

@dessalines
Copy link

Nevermind I just figured this out. I had to add a second repository:

<repositories>
        <repository>
            <id>project.local1</id>
            <name>LocalSdkAndroidRepository</name>
            <url>file:${env.ANDROID_HOME}/extras/android/m2repository</url>
        </repository>
        <repository>
            <id>project.local2</id>
            <name>LocalSdkGoogleRepository</name>
            <url>file:${env.ANDROID_HOME}/extras/google/m2repository</url>
        </repository>
    </repositories>

@takarabt
Copy link

takarabt commented Nov 6, 2015

Hello
We have the same problem and we added a local repository as above but still didn't work.
Any idea?

@paolo-rendano
Copy link

I've the same problem (in a multimodule maven project), but I discovered that if you don't make a "mvn clean package", but only a "mvn package", it works. Looking at the extended log (-X) it seems that the plugin deleted the unpacked-libs after the modules that use it.

@william-ferguson-au
Copy link
Contributor

Can you post a cut down project on Github that clearly shows the failure?

@Yrlec
Copy link

Yrlec commented Jun 27, 2016

We have the same issue. Judging from the logs it looks it the error occurs in isBuildConfigPresent. It should be fairly easy to fix it. One just needs to catch FileNotFoundExceptions and return false. Something like this:

private boolean isBuildConfigPresent(Artifact artifact, String packageName) throws MojoExecutionException { try { JarFile jar = new JarFile(getUnpackedAarClassesJar(artifact));
JarEntry entry = jar.getJarEntry(packageName.replace('.', '/') + "/BuildConfig.class");

        return (entry != null);
    } catch (FileNotFoundException e) {
        return false;
    } catch (IOException e) {
        getLog().error("Error generating BuildConfig ", e);
        throw new MojoExecutionException("Error generating BuildConfig", e);
    }
}`

@Yrlec
Copy link

Yrlec commented Jun 27, 2016

Sorry about the bad formatting. Markdown didn't like my code snippet for some strange reason.

@mosabua
Copy link
Member

mosabua commented Jun 27, 2016

Can you send this as a PR instead so you end up in the changelog?

@mosabua
Copy link
Member

mosabua commented Jul 15, 2016

Is this fixed with the 4.4.3 release I just cut?

@meletis
Copy link

meletis commented May 20, 2017

No, the problem still persists with 4.4.3.

@mosabua
Copy link
Member

mosabua commented May 3, 2019

Closing old issues as part of cleanup effort. Feel free to re-open and submit a PR with fix.

@mosabua mosabua closed this as completed May 3, 2019
@meletis
Copy link

meletis commented May 8, 2019

The problem still persists with 4.5.0 but we use the following workaround:

mvn clean && mvn install

It is just that one command with both goals together can't run:

mvn clean install

...but the workaround of two commands is not that bad.

@mosabua
Copy link
Member

mosabua commented May 9, 2019

Hm .. that shoud work .. but I cant reproduce. Maybe you can try the above suggested patch (not sure where exactly to apply that) and test it and then send a PR with the fix.

@mosabua mosabua reopened this May 9, 2019
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

No branches or pull requests

8 participants