Android Studio include maven artifact in APK (gradle) - android-studio

I have an Android project that requires the Jsoup library. I've tried everything I can think of to get the jar shaded into the APK.. I just can't get it working. Logcat tells me:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: org.jsoup.Jsoup
Does anyone know how to include/shade a maven artifact into an APK with Android Studio?

I have found the answer. The trick is to append ":sources". See an example here: http://www.alonsoruibal.com/my-gradle-tips-and-tricks/

I have seen the same type of error every time someone else adds a library with Gradle. Build is usually successful but app crashes when it tries to use the new library. Running task clean with Gradle helps.

Related

Could not find com.android.tools.build:gradle:7.5.1

So I was building out a test APK in Android Studio tonight that had to be signed. It failed and said my Gradle was out of date. So I upgraded my gradle from 7.3.3 to the newest 7.5.1
I changed the wrapper setting to distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
and then I changed my build.gradle dependency to classpath 'com.android.tools.build:gradle:7.5.1'
Note that after doing the changes, and restarting Android Studio, it did upgrade the version in the app directory.
Here's the error getting thrown below:
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all files for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:7.5.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.5.1/gradle-7.5.1.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.5.1/gradle-7.5.1.pom
Required by:
project :
Note that this was a project from a client, and I did not write this originally. These dependencies were in place, but fairly recent, and the app would build fine with it using 7.3.3. However it wouldn't let me sign my app.
I suppose I could use some wisdom on both of these issues. What I'm going to do is go back to version 7.3.3, build the signed APK again, and copy that exact error to report back here with. It was a gradle version error.
For any any Flutter noobs like myself passing through, this error occured because the Android Tools Plugin version DOES NOT match the Gradle Version:
https://developer.android.com/studio/releases/gradle-plugin#groovy
They match up just vaguely enough in number, that you would think that my line com.android.tools.build:gradle:7.5.1. uses gradle 7.5.1, but instead, Android Tools for Gradle is actually a separate entity, and at 7.3.3 as of typing this reply.
So you CAN set your Gradle to the newest version somewhere else in your project, but it has to match the compatible Android Tools version, which is set here. Its silly and confusing at first, and can easily trip up newcomers. Hopefully the versions diverge enough, or the code syntax changes for some better clarity, but as of now, this is it.

After Android Studio update. Could not parse POM, Could not resolve all files for configuration ':app:_internal_aapt2_binary'

Hello I've been looking to other similar questions about this problem but none has helped me so far, after I updated to android studio to the new version 3.6.2 I have this error when I try to run any project.
Run info:
Execution failed for task ':app:mergeDebugResources'.
Could not resolve all files for configuration ':app:_internal_aapt2_binary'.
Could not resolve com.android.tools.build:aapt2:3.6.2-6040484.
Required by:
project :app
Could not resolve com.android.tools.build:aapt2:3.6.2-6040484.
Could not parse POM https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/3.6.2-6040484/aapt2-3.6.2-6040484.pom
Content is not allowed in prolog.
Before the update the project was able to build now none of my projects build.
I tried invalidate cache and restart, I checked that I was not running in offline mode. still have the same failure. Any idea whay this could be and how I could fix it?
if you have problem with gradle
change your android stadio version to 3.6.2 or lower
file>project Strcture>
change to 3.6.2 and OK
I fixed the Error by going to my username and deleting .gradle, .AndroidStudio3.6 and .AndroidStudio3.5 folders. after I restarted android studio to download the folders again and resetting them. It worked.

No incremental compile snapshot data available gradle error

I am launching a Gradle task and it gives me an error like No incremental compile snapshot data available. I've searched online and I can't find a sufficient description for this. Do you know what exactly raises this error?
What gradle version are you using, found an old bug in v4.10: https://github.com/gradle/gradle/issues/6612
My project is using gradle 4.10 version. However, gradlew.bat clean build --refresh-dependencies solved this problem for me.
By Deleting the .gradle folder of Android Project.
Then do gradle sync and build apk.
It will solve this problem

Kotlin app build failed due to "Could not initialize class com.intellij.ide.highlighter.JavaFileType"

I've just updated Android Studio to 2.2 and now my Kotlin project won't build. The gradle synch works fine, but when attempting to build I'm immediately presented with an error that reads:
Error:Execution failed for task ':app:compileDebugKotlin'.
> Could not initialize class com.intellij.ide.highlighter.JavaFileType
I've checked that my Kotlin plugin is up to date. This error sounds like something to do with the IDE and highlighting Java code? Any help would be appreciated.
Open Tools | Kotlin | Configure Kotlin Plugin Updates in the main menu,
then choose Check for Updates. Be sure that yo're using Stable channel.
Close Android Studio, go to your project's directory, and delete build and app/build folders. Run Android Studio. Deleted folders would be recreated.
Hope it will help
In my case the kotlin plugin was not updated as #piotrek1543 said in other answer.
In addition to that the build.gradle had an old Kotlin version number 1.0.1-2 and the IntelliJ said in a warning on top of to switch to the current bundled version 1.0.4.
Now with the kotlin version like this the error is gone:
ext.kotlin_version = '1.0.4'

Error:This project does not use the Gradle build system, even though it was build in gradle system before

My project was build initally with bradle build system in android studio after I switching branches in git I got the following error.
This project does not use the Gradle build system. We recommend that you migrate to using the Gradle build system.
When i try exetuting gradle task I get error :
Error:Android Source Generator: [project-name] AndroidManifest.xml file not found , Even though I have the file in proper place.
I have been trying to fix this from several days. I have tried re-importing the project, clone the project again. Any help is gladly welcome.
Thanks,

Resources