Java-Module using Android API with Gradle - android

I am currently migrating an Android project from classic IntelliJ IDEA format to Gradle. In my project, there are modules that are using the Android SDK without being Android modules. They are plain Java modules that use the Android SDK instead of a JDK.
How can I achieve that with Gradle?
The approach I can think of is to apply plugin: 'java' and somehow configure the Android SDK as the used JDK or as a dependency. But I don't know how to do it exactly...

I have just revisited Eugen's first hint and "suddenly" it works.
So, basically you need to apply the Java plugin and add Android as a provided dependency.
apply plugin: 'java'
configurations {
provided
}
dependencies {
provided 'com.google.android:android:2.2.1'
}
#Eugen: Maybe you'd like to repost this to receive your credits.

Related

Errrors, when configuring react-native project (building gradle) with android studio. I want to build gradle scripts for using firebase with my app

I ran into this problem after i updated android studio and the gradle version. Here's what i did step by step:
First i got the following error:
Build Gradle Error Could not get unknown property 'compile'
I checked stackoverflow and it said that changing "compile" with "implementation" would solve the problem, and so i did that.
Another issue was that maven was deprecated. So i used, maven-publish instead of maven.
Now i am getting the following error:
12:24 PM Gradle sync failed: Could not find method uploadArchives() for arguments [build_a5ye7ixpcm9qfmol93kt3ucl1$_run_closure4#73b8042a] on project ':expo-application' of type org.gradle.api.Project. (17 s 537 ms)
In this part of code in build.gradle(:expo-application):
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: mavenLocal().url)
}
}
}
I am not really familiar with android studio or java. I just use Android Studio for configuring react native apps for android. Can someone please help me resolve these issues..
Thank you
As of Gradle 7.0, compile has been removed in favor of api. When you changed compile to implementation, you effected the transitive properties of the libraries. I'm not sure where you read that changing compile to implementation was the correct answer, but it isn't. api is a much closer approximation to compile. This chart gives a fairly easy to understand explanation of why this is. You should change the implementation to api and make sure you are using the java-library plugin instead of the java plugin. This should allow gradle to see the UploadArchives method. However, this wil cause a new issue.
As of Gradle 6.0, UploadArchives is also deprecated along with the maven plugin. You should consider using the maven-publish plugin instead. This will ensure your build continues to work in future Gradle releases.
So, to summarize, make sure your plugins look like this
apply plugin: 'java-library'
apply plugin: 'maven-publish'
and update your code to use publishing instead of UploadArchives. More information on this can be found in the current Gradle user guide here.
Alternatively, you can downgrade your gradle version to something before 7.0 and just ignore all the deprecation warnings. The choice is yours.

Can I transform compiled classes using Byte Buddy during compilation?

I need to modify some class in Flutter framework during compilation of my Flutter application.
Thought, it's a good idea to use the byte-buddy-gradle-plugin for this purpose.
Added this into my app/build.gradle:
apply plugin: "net.bytebuddy.byte-buddy-gradle-plugin"
byteBuddy {
transformation {
plugin = "com.example.BuildPlugin"
// classPath = ...
}
}
BuildPlugin is executed succesfully on compileDebugKotlin task, but it processes only my project classes.
Is there any possibility to point it to flutter.jar somehow, maybe using classPath transformation parameter?
I tried to use this part from plugin README:
configurations {
examplePlugin "foo:bar:1.0"
}
with some modifications, but got "Gradle DSL method not found: 'examplePlugin()'" error.
Unfortunately, this is not really compatible to how build pipelines work. What you can do is that you use the shade plugin to copy a dependency's code into your project and then process it from there. Otherwise, Java agents would be the solution for this but Android does not support it.
I solved it by using Android Transform API and Javassist.
Please check my GitHub if anyone is interested how.

Gradle: "apply plugin" at the top or at the bottom

Has the same effect add the "apply plugin" at the beginning or end of the file build.gradle in Android Studio projects?
For example to add the 'com.google.gms.google-services' plugin, Firebase official documentation recommends adding at the end, but I've seen other codes add it at the beginning.
I know the question seems irrelevant, but I'm developing a plugin for Android Studio to manage dependencies and have this doubt.
Thanks in advance
Gradle scripts are interpreted top to bottom so order can be important. Keep in mind that gradle has a configuration phase and an execution phase so sometimes order isn't important. It's common to apply your plugins at the top of the script since plugins often add extension objects and tasks to the gradle model which can then be configured lower down in the build script.
For example, you can't do the following because the test task is added by the java plugin:
test {
include 'org/foo/**'
}
apply plugin: 'java'

How to Create a SDK in Android Studio form the app

I have a Android app and now I have to make a SDK form the app. So other apps can use my SDK by just putting a compile time dependency I dont find many sources in Internet can some one please help me in this regard.I am using Andorid Studio
I want to build a SDK similar to MobiHelp SDK see this link : https://github.com/freshdesk/mobihelp-android
If your SDK is an Android-Library, declare
apply plugin: 'com.android.library'
instead of
apply plugin: 'com.android.application'
in the corresponding build.gradle. You will get an .aar-File (Android ARchive) that would need to be refereced from others in order to use your SDK.
If your SDK is a plain-old-java-Library (no Android resources) you also can use Maven to package it as jar.

Dexguard conflicting with other plugins in Android development

I have been using Dexguard for my Android project, and it's been working fine until recently I had to use a another plugin. Because the way the other plugin is built, it is required that the project applies either "com.android.application" or "com.android.library". but since the dexguard plugin is an extension of the com.android.application which got replaced by dexguard, I can't use the other plugins that requires the "android" plugin.
//apply plugin: 'android'
apply plugin: 'dexguard'
Does anyone know if there's a way to get around this? I have contacted the authors of the plugin but it won't be practical to bother every plugin author for a solution.
Reference to my problem:
Dexguard plugin specification
And here's the plugin (android-apt) I'm trying to use that requires plugin: Android and only Android not dexguard.
The latest DexGuard plugin (6.1.03) works alongside the Android plugin (1.0.0), instead of extending it. This should improve its compatibility with other third-party plugins.

Categories

Resources