christiandeange / aaraar

A plugin for creating a merged aar file.
Apache License 2.0
32 stars 2 forks source link

empty classes.jar #5

Closed GMCristiano closed 1 year ago

GMCristiano commented 1 year ago

With the last stable version 0.0.8 im getting an empty classes.jar file inside aar.

Using this configurations:

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
afterEvaluate {
  publishing {
    publications {
      maven(MavenPublication) {
        from(components.release)
      }
    }
  }
}

tried to use publish varient with no success.

With previous 0.0.8-SNAPSHOT from last week using from(components.releaseEmbedAar) was working fine.

The sample project sample_aaraar that i game you, has the same problem. Am I missing something?

GMCristiano commented 1 year ago

Another odd new issue

  publication.from(components.release)
  publication.artifact androidSourcesJar

using artifact androidSourcesJar from task androidSourcesJar(type: Jar) gets this error when publishing

christiandeange commented 1 year ago

Should you be running proguard that early? I suspect that proguard thinks many of the things in your library module aren't being used (maybe because they're used by another project depending on it) and probably strips everything out. What you probably should be doing is instead embedding your proguard rules (if any) into your aar and running proguard in a higher-level module. Can you try with something like this instead?

android {
  defaultConfig {
    consumerProguardFiles 'proguard-rules.pro'
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }
}

See this post for more info: https://stackoverflow.com/a/50819864/1403479

christiandeange commented 1 year ago

For the second issue (and next time, please file a separate ticket for unrelated issues) this perhaps looks like an issue in your project. Perhaps you are trying to add sources to the publication in more than one place. I just added a commit to the sample app to verify that adding sources as an artifact works as expected.

GMCristiano commented 1 year ago

Same result with R8 turned off. the only change I did was switching from the old 0.0.8-SNAPSHOT to the new 0.0.8. and switch to componente.release.

Maybe this only happens with already compiled AARs just like tha sample that i gave you.

Sorry about the 2º issue. I will do more investigations on Monday.

GMCristiano commented 1 year ago

Hi,

sorry I just realised that i was missing my own publish configuration that works.

android {
    publishing {
        singleVariant('release')
    }
}
afterEvaluate {
    publishing {
        publications {
            maven(MavenPublication) {
                from components.release
            }
        }
    }
}

I just got empty classes.jar from aar when using your configurations...

    buildTypes {
        release {
            minifyEnabled false
        }

        publish {
            initWith release
            matchingFallbacks = ['release']
        }
    }
aaraar {
    isEnabledForVariant { variant ->
        variant.name == "publish"
    }
}
afterEvaluate {
    publishing {
        publications {
            maven(MavenPublication) {
                from components.publish
            }
        }
    }
}

here is my sample (with no empty publish.properties to use publishToMavenLocal) sample_aaraar.zip

Hope this helps.

christiandeange commented 1 year ago

Ah yep, after testing your sample project it looks like that additional configuration is needed:

android {
    publishing {
        singleVariant('publish')     // or whichever variant you intend to push to maven
    }
}

After adding that, the plugin seems to work as expected.

This might be a side effect of the new variant-specific publishing configuration that 0.0.8 introduced. I'll look into updating the documentation with this new requirement if necessary.

christiandeange commented 1 year ago

It looks like both of the originally-reported issues are actually related, and only present when using AGP 8. The old method of adding a source jar as an artifact now only needs to be done inside the singleVariant(...) block, so I think you should be able to delete the custom androidSourcesJar task that used to generate this artifact.

You can look at how I changed the sample library in this commit to see how it seems to work now. Let me know if that solves your issues and we can resolve this issue if that's the case.

GMCristiano commented 1 year ago

The second issue was a side a affect of the first problem.... But yeah, this looks mandatory, and if there is no custom stuff, withSourcesJar and withJavadocJar can be simplified this way.

publishing {
    singleVariant('release') {
    withSourcesJar()
        withJavadocJar()
    }
}

Thanks for the help. the plugin is stable ;) And I learned how to use Gradle Module Metadata the right way in the process.