Extension function can't be imported from library - android

After updating android gradle plugin version from 3.5.0 to 4.1.0-alpha06, extension function defined in one of my android library project can't be imported in consuming projects. (Normal classes can be used without any issue)
I've compared both the jars (one built-with 3.5.0 and another built-with 4.1.0-alpha06) and found out that the META-INF directory missing in new jar.
Working Jar - Built-with 3.5.0
Not Working Jar - Built-with 4.1.0-alpha06
How to fix this issue ?

You need to keep kotlin_module in apk/META-INF
So check your build.gradle and remove this line
packagingOptions {
exclude("META-INF/*.kotlin_module")
}

Related

Releasing Android Library without NDK dependency

I am building a .aar Library that is partially written in C++ and uses OpenCV.
When i am assembling the Library i get a .aar with everything included and i can import it into a different project. When building the project i get the error, that i still need the correct ndk in the project which imports the .aar. This is not good if i want to give the library to others.
Shouldn't the JNI part of the library already be compiled so i don't need the NDK if i already have the .aar?
How can i remove the dependency from the .aar?
Edit:
The Error is No version of NDK matched the requested version 20.0.5594570. Versions available locally: 17.3.6528147, 21.0.6113669
I include the .aar by putting it in the libs/ folder in the module and adding '*.aar' to the build.gradle fileTree implementation.
The reason for it was the automatic stripping of the native part of my library.
Explaination here: https://stackoverflow.com/a/62320616/4284799
Solution 1: Change gradle version in the projects build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
Solution 2: install a ndk and set it in the local.properties
ndk.dir=/path/to/android-sdk/ndk-bundle

Android Studio generates R file only for modules with no module dependencies in multi-module project

After updating to AS 3.3.1 from 3.2.something I've got a strange bug: R file is generated only for modules that do not implement any other modules. I still can compile project or go to declaration via cmd+B, but every resource file like R.layout.activity_main is highlited with an "unresolved reference" message, until I remove every module implementation from module build.gradle and resync the project.
As far as I've noticed, the problem does not related with android gradle 3.3.0 or kotlin 1.3, since my old projects are affected as well.
What I've already tried:
Clean/Rebuild project
Invalidate cache
Resync Gradle
Switch to Android Gradle 3.2.1
delete .idea directory
Here's my project, module build.gradle example and used libraries.
For example, if I comment implementation(project(":presentation")) line in mainscreen/build.gradle.kts, the error disappears. Obviously, it isn't the solution.
UPD: SOLVED
Solution: you have to specify different package names in each AndroidManifest.xml files, i.e. com.mycompany.example.launcher for launcher module, com.mycompany.example.presentation for presentation module et cetera.
[solution1]
You can delete the old version of gradle from your system and start installing its new version.
[solution2]
Or remove Android Studio and reinstall it

Include aar in sbt build

I have an android project here that includes local file aars in gradle via
dependencies {
compile project(':packagename_0.3')
}
I am unable to translate that to the appropriate sbt syntax so that during the build sbt is actually able to resolve the dependencies. Does anyone have an idea ? I checked scala on android but still did not manage to find a working way. Does anyone have a suggestion?
Well I ended up extracting the jars from the aars and adding them to the default unmanagedBase folder (src/main/libs).
You need to add a setting:
localAars += path_to_aar_file

AChartEngine And Android Studio

I have to create an application that makes extensive use of charts.
Reading the web I chose achartengine that seems to have everything I need.
I downloaded the jar file, I plugged in the libs folder, I selected "add to library" and I lunch the gradlew clean.
Result in the sources where I do the import of org.achartengine.xxxx I always returned the error that fails to resolve symbols .
Do you have suggestions?
Thank you
Andrea
I am able to use this library in my Android Studio project, this topic explains how to add AChartEngine repo to your project.
What I did:
Added following to project-wide build.gradle (one from the project root):
allprojects {
repositories {
...
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
For every module that uses the library, add this to its build.gradle (you may put this to the top-level build.gradle if it should be included in all modules):
dependencies {
...
compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}
Now I can use the library in the project, I see the classes in code assist popups and build runs as succeeds.
It seems like the new version (1.2.0) is not available for download anymore in the http://www.achartengine.org/ site. and that's why the gradle/maven method doesn't work (or the snapshot file was removed).
I succeeded using and adding it to my project by downloading the jar file from here:
https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip

Android/Gradle: Where is this dependency embedded?

I'm using the new Android build system that is based on Gradle, together with the early access preview Android Studio. Now, I have two projects: an Android library project, and an Android app project (basically a demo for the library).
In the library project I have added a dependency to the gson library, so my build.gradle file looks like this:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'com.google.code.gson:gson:2.2.+'
}
Still, everything works fine and dandy and I'm able to use gson in my library and then my app. But I want to understand where this library is embedded. I've opened both the .aar that is built by the library project and the .apk of the demo app. I was expecting to find the jars for the two dependencies in at least one of these, but I didn't.
So where are they?
From Android Tools website:
These items, plus the output of the compilation of the project’s own source code, are sent to dex for bytecode conversion and inclusion in the final APK.
In other words, they are in your *.dex file inside the APK.
As #SharkyXTS said, the code from any external dependencies is compiled into the final .dex file inside your APK. The reason why you can't find any references to these dependencies in the .aar is because there aren't any.
The .aar format is only supported through Maven for now, so dependencies are found through there. I believe there are plans to eventually support local .aar dependencies (without Maven), but the Android plugin isn't quite there yet. You can see this issue for more information.

Categories

Resources