Unresolved reference when using a generated AAR with Composables - android

I'm in the process of porting my FloatingActionButtonSpeedDial library to Compose and I've reached the step where I should publish the new Compose library to maven central but, when I generate the AAR, all the composable classes throw an Unresolved reference.
The crazy thing is that the the enum on the same package is perfectly fine and so is the AAR of the classic view library. So, the issue seems to affect only functions annotated with #Composable.
The issue happens with both a debug and release AAR so should not depend on minimization on release.
And of course the issue does not happen if I import the gradle module directly instead of using the AAR.
Do I need to do something special to generate an AAR with Composable?
This is build.gradle of the library module

The issue is caused by the packagingOptions:
packagingOptions {
resources {
exclude '.readme'
exclude 'LICENSE.txt'
exclude 'fabric/*.properties'
// Exclude the Firebase/Fabric/other random properties files
exclude '/*.properties'
// Exclude AndroidX version files
exclude 'META-INF/*.version'
// Exclude consumer proguard files
exclude 'META-INF/proguard/*'
exclude 'META-INF/*.properties'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/NOTICE.txt'
exclude "META-INF/AL2.0"
exclude "META-INF/LGPL2.1"
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
exclude 'META-INF/*.kotlin_module'
// for byte-buddy
exclude "META-INF/licenses/ASM"
pickFirst "win32-x86-64/attach_hotspot_windows.dll"
pickFirst "win32-x86/attach_hotspot_windows.dll"
}
}
And, in particular by the exclude 'META-INF/*.kotlin_module': this file is needed to access top-level members.
It would be better clear this exclusion list and only add what's necessary to get the project to build.

The scope of these classes seems to be package private, compared to class SpeedDialState. Maybe take a look at other composable libraries, in order to see how they do it:
https://github.com/jetpack-compose/jetpack-compose-awesome#libraries

Related

Excluding optional sub-dependency from Android library published to Maven Central

I am building an Android library that depends on PayPal Android SDK.
I am trying to exclude card.io credit card scanning from the PayPal SDK.
compile('com.paypal.sdk:paypal-android-sdk:2.13.3') {
exclude group: 'io.card'
}
The problem is, when I push my library to Maven Central, and include it in example project,
card.io native libraries are included in the build anyway, and they increase the apk size by ~11 megabytes.
I have tried adding this to my build.gradle
packagingOptions {
exclude 'lib/arm64-v8a/libcardioDecider.so'
exclude 'lib/arm64-v8a/libcardioRecognizer.so'
exclude 'lib/arm64-v8a/libcardioRecognizer_tegra2.so'
exclude 'lib/arm64-v8a/libopencv_core.so'
exclude 'lib/arm64-v8a/libopencv_imgproc.so'
exclude 'lib/armeabi/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer_tegra2.so'
exclude 'lib/armeabi-v7a/libopencv_core.so'
exclude 'lib/armeabi-v7a/libopencv_imgproc.so'
exclude 'lib/mips/libcardioDecider.so'
exclude 'lib/x86/libcardioDecider.so'
exclude 'lib/x86/libcardioRecognizer.so'
exclude 'lib/x86/libcardioRecognizer_tegra2.so'
exclude 'lib/x86/libopencv_core.so'
exclude 'lib/x86/libopencv_imgproc.so'
exclude 'lib/x86_64/libcardioDecider.so'
exclude 'lib/x86_64/libcardioRecognizer.so'
exclude 'lib/x86_64/libcardioRecognizer_tegra2.so'
exclude 'lib/x86_64/libopencv_core.so'
exclude 'lib/x86_64/libopencv_imgproc.so'
}
but it only works when I add it to example app's build.gradle, not to my lib's build.gradle.
I would like to avoid users of my lib having to add this to their app's build.gradle.
A bit more details:
I am not actually pushing the library to maven central right away.
I am pushing it to a staging repository at oss.sonatype.org and pulling it from there using this:
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/staging/"
}
}
When I manually look at the .pom file from the repo, I am not seeing any exclusions added for the PayPal dependency.
I tried excluding both group 'io.card' and module 'android-sdk' from PayPal dependency, and then the exclusion DOES show in the .pom file,
but the card.io native libraries are still included in the final build.
I am clearing gradle cache after creating repositories to make sure it always downloads the latest version of my SDK from the staging repo.
One ugly solution that works is to add exclude group: 'io.card' when including my library, but I would like to avoid that.

How to exclude package-info.java files from dex?

I have a multi-module Android application and when I build the release APK, I get this dex error:
java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/XX/package-info;
I do of course have a package-info file in all my modules and they all have the same name.
Why does dex even care about package-info files, and how can I configure it to ignore them?
Note: I do NOT want to enable multi-dex
The solution is to exclude the package-info files from the jar files.
Example code to use in build.gradle files
for java-modules:
jar {
exclude('com/**/package-info.*')
}
for android-modules:
android {
sourceSets.main.java.filter.exclude 'com/**/package-info.*'
}
Works with:
Android Studio 3.0 Canary 5
Gradle 4.1-milestone-1
Android gradle plugin: 3.0.0-alpha5
Note: you can of course only then exclude the package-info files if they don't contribute to your build!
e.g. when you use immutables style-configuration in your package-info file then you cannot exclude the files from the build, because then the names of the generated files may change!
Try with using packagingOptions inside android tag in build.gradle for app module.
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
More: Packaging

How Can I Include Only Certain Source Files In Gradle

I have a bunch of code in an Android Studio Project that was added from another project. When I originally added it, I wasn't ready to start using it so I researched how to exclude source files and added this to build.gradle:
sourceSets {
main {
java {
//needed until we integrate these classes
exclude 'org/odk/collect/android/**'
}
}
}
Now I'm ready to start using some of these classes. What I'd like to do is specify individual files which should be included. Unfortunately the include statements don't seem to have any effect as gradle will still report that a certain package doesn't exist.
In fact it doesn't seem as though include does anything. I would have liked it to have the opposite effect of exclude. So that, if I change my config to only specify which files to include, only those are included. Sadly, this is not the case.
I've also tried being more explicite with my exclude's and specifying 20+ packages which should be excluded and the individual classes I want included but it didn't work for me. Here's and example of that:
EDIT: this has a bug in it, I didn't intend for exclude 'org/odk/collect/android/logic/**' to be in there. I also didn't need the includes while excluding explicitly. I shall post what finally worked in an solution.
sourceSets {
main {
java {
//needed until we integrate these classes
exclude 'org/odk/collect/android/activities/**'
exclude 'org/odk/collect/android/adapters/**'
exclude 'org/odk/collect/android/application/**'
exclude 'org/odk/collect/android/database/**'
include 'org/odk/collect/android/exception/**'
exclude 'org/odk/collect/android/external/**'
exclude 'org/odk/collect/android/listeners/**'
exclude 'org/odk/collect/android/logic/Drive*'
exclude 'org/odk/collect/android/logic/File*'
include 'org/odk/collect/android/logic/FormControlle'
exclude 'org/odk/collect/android/logic/FormDetails*'
exclude 'org/odk/collect/android/logic/H*'
exclude 'org/odk/collect/android/logic/P*'
exclude 'org/odk/collect/android/logic/**'
exclude 'org/odk/collect/android/picasa/**'
exclude 'org/odk/collect/android/preferences/**'
exclude 'org/odk/collect/android/provider/**'
exclude 'org/odk/collect/android/receivers/**'
exclude 'org/odk/collect/android/tasks/**'
exclude 'org/odk/collect/android/utilities/**'
exclude 'org/odk/collect/android/views/A*'
exclude 'org/odk/collect/android/views/D*'
exclude 'org/odk/collect/android/views/E*'
exclude 'org/odk/collect/android/views/H*'
include 'org/odk/collect/android/views/MediaLayout'
include 'org/odk/collect/android/views/ODKView'
exclude 'org/odk/collect/android/views/T*'
exclude 'org/odk/collect/android/widgets/**'
}
}
}
Now, I know you might wonder, why even have all these files in the project in the first place? Why don't you just delete the unused ones and add them again when you're ready to implement them? And the reason is that I want to keep the git history of these files intact so that features like blame and annotate properly attribute the code lines to their original author.
Some other configurations which didn't work:
includes first, then exclude
include 'org/odk/collect/android/exception/**'
include 'org/odk/collect/android/logic/FormController.java'
include 'org/odk/collect/android/views/A*'
include 'org/odk/collect/android/views/MediaLayout*'
include 'org/odk/collect/android/views/ODKView*'
include 'org/odk/collect/android/widgets/**'
exclude 'org/odk/collect/android/**'
example errors:
package org.odk.collect.android.logic does not exist
package org.odk.collect.android.exception does not exist
exclude first then includes
exclude 'org/odk/collect/android/**'
include 'org/odk/collect/android/exception/**'
include 'org/odk/collect/android/logic/FormController.java'
include 'org/odk/collect/android/views/A*'
include 'org/odk/collect/android/views/MediaLayout*'
include 'org/odk/collect/android/views/ODKView*'
include 'org/odk/collect/android/widgets/**'
example errors:
package org.odk.collect.android.logic does not exist
package org.odk.collect.android.exception does not exist
Just leaving this here for someone who might come along later. This answer shows how you can use HashSet to include just the files you need. So for instance, if you just wanted to include FileA.java and FileB.java and exclude everything else, you can use the following configuration:
sourceSets {
main {
java {
setIncludes(new HashSet(['com/somepackage/FileA.java',
'com/somepackage/FileB.java']))
}
}
}
Having an exclude for every class not included works. I haven't had any luck with includes. I would have preferred specifying only the files to include so if anyone knows how to do that, post another solution. I left my include statements there, but commented so it is more obvious which files I'm not excluding.
This is a quite verbose way of doing things. And I don't doubt there is a better way out there.
sourceSets {
main {
java {
//needed until we integrate these classes
exclude 'org/odk/collect/android/activities/**'
exclude 'org/odk/collect/android/adapters/**'
exclude 'org/odk/collect/android/application/**'
exclude 'org/odk/collect/android/database/**'
// include 'org/odk/collect/android/exception/**'
exclude 'org/odk/collect/android/external/**'
exclude 'org/odk/collect/android/listeners/**'
exclude 'org/odk/collect/android/logic/Drive*'
exclude 'org/odk/collect/android/logic/File*'
// include 'org/odk/collect/android/logic/F*'
// exclude 'org/odk/collect/android/logic/FormDetails*'
exclude 'org/odk/collect/android/logic/H*'
exclude 'org/odk/collect/android/logic/P*'
exclude 'org/odk/collect/android/picasa/**'
exclude 'org/odk/collect/android/preferences/**'
exclude 'org/odk/collect/android/provider/**'
exclude 'org/odk/collect/android/receivers/**'
exclude 'org/odk/collect/android/tasks/**'
exclude 'org/odk/collect/android/utilities/**'
exclude 'org/odk/collect/android/views/Ar*'
// include 'org/odk/collect/android/views/AudioButton'
exclude 'org/odk/collect/android/views/D*'
exclude 'org/odk/collect/android/views/E*'
exclude 'org/odk/collect/android/views/H*'
// include 'org/odk/collect/android/views/MediaLayout*'
// include 'org/odk/collect/android/views/ODKView*'
exclude 'org/odk/collect/android/views/T*'
exclude 'org/odk/collect/android/widgets/A*'
exclude 'org/odk/collect/android/widgets/B*'
exclude 'org/odk/collect/android/widgets/D*'
exclude 'org/odk/collect/android/widgets/E*'
exclude 'org/odk/collect/android/widgets/G*'
exclude 'org/odk/collect/android/widgets/I*'
exclude 'org/odk/collect/android/widgets/L*'
exclude 'org/odk/collect/android/widgets/O*'
// include 'org/odk/collect/android/widgets/QuestionWidget'
exclude 'org/odk/collect/android/widgets/SelectMulti*'
exclude 'org/odk/collect/android/widgets/SelectOneAuto*'
// include 'org/odk/collect/android/widgets/SelectOneWidget'
exclude 'org/odk/collect/android/widgets/Si*'
exclude 'org/odk/collect/android/widgets/Sp*'
exclude 'org/odk/collect/android/widgets/St*'
exclude 'org/odk/collect/android/widgets/T*'
exclude 'org/odk/collect/android/widgets/U*'
exclude 'org/odk/collect/android/widgets/V*'
// include 'org/odk/collect/android/widgets/WidgetFactory'
}
}
}

Android Proguard build Duplicate Zip

In my android application i have multiple third party libraries in libs folder
ex -: httpcore-4.2.4.jar , httpmime-4.2.5.jar,twitter4j-core-4.0.1.jar
these libraries are not duplicated and i'm pretty sure with that , but when i create the proguard release i get this error
(Duplicate zip entry [twitter4j-core-4.0.1.jar:META-INF/MANIFEST.MF])
.... (This error occurs for all of the library(libs)
I refereed this link to overcome with issue , i tried every option of it , but no luck with that ,
Proguard warnings "can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry)"
Is there any way to specify filters on the input jar
Your libraries are not duplicated, but some info files inside of several libraries are.
The best solution is to include in your build.gradle. inside the "android" section something like this:
android{
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LGPL2.1'
}
}
By the error message that you included here I will guess that adding this exclude will solve your problem:
exclude "META-INF/MANIFEST.MF"

Android gradle duplicate LICENSE.txt file again

I'm getting this error (AGAIN!) on android. Recently updated to the latest version of gradle 0.7.3 and also to the latest version of espresso framework (1.1) and I'm back to the infamous "duplicate file" bug.
Execution failed for task ':mobile:packageTesttype'.
Duplicate files copied in APK META-INF/LICENSE.txt File 1: /Users/mwolfe/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.2.4/dba4d4d224e2ca872af5be8d2992777583145478/httpmime-4.2.4.jar
File 2:
/Users/mwolfe/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.2.4/dba4d4d224e2ca872af5be8d2992777583145478/httpmime-4.2.4.jar
I already have set my build.gradle file to exclude these files. The app assembles fine for debug/release and runs fine, However building/running for test it fails. Specifically when I try to run instrument tests with the followng command is when I get the error mentioned above.
gradle connectedCheck
I have a library project as well and have tried every which way to add the exclusions to both build files. This specific dependency is from the library project. Both of them have the following exclusions
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
I've also tried with removing the META-INF part above as it shows in the espresso docs here: https://code.google.com/p/android-test-kit/wiki/Espresso#Espresso_Setup_Instructions
I know I can delete these files from the jars but it's quite a pain.
Try to include other variations too...Copy and paste this:
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}

Categories

Resources