I was just wondering why that line of code exists in my gradle configuration
Android gradle apply plugin: 'com.android.application'
Gradle is a general-purpose build system. It uses plugins to teach it how to build different types of software. com.android.application is a Gradle plugin that teaches Gradle how to build Android applications, just as com.android.library is a plugin that teaches Gradle how to build Android library projects. There are many plugins available for Gradle, to teach it how to build other sorts of systems or augment other plugins.
As describe in the official website:The first line in the build configuration applies the Android plugin for
Gradle to this build and makes the android block available to specify
Android-specific build options.
Related
In my React Native app, I got an error about incompatibilities with gradle 6, so I looked in my project structure to find out which version of gradle I was running in my project. I found this line in gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
and this line in build.gradle
classpath("com.android.tools.build:gradle:3.4.2")
What I Want To Know: What's the difference between the reference to gradle in each of these files? In other words, how is version 5.5 being used in my project, and how is 3.4.2 being used?
distributionUrl represents Gradel Version where as classpath represents Android Gradle plugin version.
Gradel vs Android Gradle plugin: Reffer this difference between android gradle plugin and gradle
Gradle is the build system.
You can use it with a lot of plugins. One of these is the plugin for Android.
It is used to provide processes and configurable settings that are specific to building and testing Android applications.
For greater details and mapping of the above two type of versions refer the following URLs
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
https://developer.android.com/studio/releases/gradle-plugin#updating-plugin
I hope this answer has cleared your doubts.
Recently I have had to update my project to use Gradle 4.4 from 4.1.
i.e.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
in my gradle-wrapper.properties file.
However, this is incompabitble with the fabric plugin
apply plugin: 'io.fabric'
As since the gradle update, I now get build errors when syncing my project.
Such as:
Error:Could not get unknown property 'manifestFile' for task
':Module:generateVariantFlavorRFile' of type
com.android.build.gradle.internal.res.GenerateLibraryRFileTask.
Does anyone know when/if there will be a new plugin update that is compatible with gradle 4.4+?
So my project included feature modules, where in the the base module's build.gradle, I apply the fabric plugin. i.e. apply plugin: 'io.fabric'
It turns out that gradle version 4.4 + does work but you need to add the following:
crashlytics { instantAppSupport true }
in your base module's build.gradle. I didn't actually have an instant app, but even with feature modules in appears that this line is needed.
More info on how this can be added can be found here:
How do I integrate Crashlytics with Android Instant Apps?
Is there any way or workarounds or just hints to make plugins from gradle and gradle-experimental working together?
For example to mix those two versions:
com.android.tools.build:gradle:1.3.1
com.android.tools.build:gradle-experimental:0.3.0-alpha4
I have an existing project which uses some external plugins (app/build.gradle):
apply plugin: 'com.android.model.application'
apply plugin: 'com.android.databinding'
apply plugin: 'com.jakewharton.hugo'
in my root build.gradle I have:
com.android.tools.build:gradle-experimental:0.3.0-alpha4
Issues which I have:
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.databinding']
> java.lang.NullPointerException (no error message)
or
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.jakewharton.hugo']
> 'android' or 'android-library' plugin required.
Without other plugins my project works fine (I have Android Library with some NDK code which is called from my main project. Problem occurs when I add mentioned plugins on any others.
And the question is - is it a gradle-experimental issue or issue of each plugin (hugo, databinding, apt, probably much more).
Or maybe you have any hints if there is any other way to have app with current stable gradle plugin and library (with NDK code) which uses gradle-experimental?
What I want to avoid is a dealing with *.mk files and (as full as possible) Android Studio support. Bigger picture is to prepare .aar library with NDK code (just simple computation) which will be able to plug in to existing projects.
I've been able to mix gradle stable and -experimental android plugins without any issues by using recent versions in my project.
You should be able to define both dependencies inside your project's build.gradle file:
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.3.0-alpha7'
classpath 'com.android.tools.build:gradle:1.4.0-beta6'
}
and then either use apply com.android.(application|library) or com.android.model.(application|library) from your various module's build.gradle files.
Haven't used experimental plugin yet, but I guess, you can divide your project into 2 Gradle modules and use standard Android Gradle Plugin for the application module and new experimental plugin in the NDK module.
#ph0b is right, I am just giving an update of that answer.
you will need in your gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
and in your project build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath "com.android.tools.build:gradle-experimental:0.7.3"
}
I understand as Gradle is build tool and android provide plugin for android build.
When Gradle meet "apply plugin : 'android'" gradle-0.13.3.jar will be downloaded somewhere. right??
But I can not find android plugin anywhere.
How does Gradle build android using plugin ??
apply plugin: "xyz" applies a plugin that's already on the build class path. To get a third-party plugin such as the Android plugin on the build class path, a plugin dependency has to be specified in a buildscript block. For details on this, check the Gradle User Guide or the Android Gradle plugin docs.
(Gradle 2.1 introduces a new plugins block that allows to apply plugins available from http://plugins.gradle.org/ without specifying a plugin dependency.)
I have an Android project in IntelliJ IDEA. It consists of two modules: app and library. App depends on library and library depends on app (Yes, it's not good, but I have what I have and can't change this). IDEA in project settings warn me about circular dependencies, but project builds correctly. Project structure looks like this:
project
|__app
| |__src
| |__build.gradle
|__libarary
| |__src
| |__build.gradle
|__build.gradle
|__settings.gradle
Now I'm trying to migrate to new Android build system based on Gradle and have a trouble here. In my build.gradle from app module I add dependency on library
compile project(":library")
Also I tryed to add dependency in library on app like
compile project(":app")
But gets error from build system, when gradle trys to assemble library module:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> Module version project:app:unspecified depends on libraries but is not a library itself
What I can do with this without changing project structure
This parameters have changed.
You should now refactor:
In the library project use:
apply plugin: 'com.android.library'
In the app project use:
apply plugin: 'com.android.application'
In the library project use:
apply plugin: 'android-library'
In the app project use:
apply plugin: 'android'
Make sure you have the newest Android tools:
classpath 'com.android.tools.build:gradle:0.5.+'
If you arrive here searching for the same error with Android 3.0 you should know the current workaround is:
downgrade to kotlinVersion = '1.1.2-2'
and disable incremental build in gradle.properties kotlin.incremental=false
The issue is planned for the next alpha https://issuetracker.google.com/issues/38447344