Android Gradle build and circular dependency - android

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

Related

"Module not specified" error in application project to library project conversion

I need to convert an android-studio application project to library project. For this, I have followed official documentation from https://developer.android.com/studio/projects/android-library#Convert
I.e. changed
apply plugin: 'com.android.application'
to
apply plugin: 'com.android.library'
After that, it's giving "Module not specified" error in run configuration setting. I have tried syncing gradle files, invalidating and restarting android-studio, but "Module not specified" error has not been resolved.
How to resolve this error in converting application project to library project?
It is because a library module cannot run as app.
You need to new a module(say newapp) and set its buuild.gradle apply plugin: 'com.android.application', then edit the root settings.gradle include 'newapp'.
Give it a go.
Generate the aar file by running directly the gradle build task, selecting it from the gradle tasks of the app module:

Jenkins build failed with stripe Could not determine the dependencies of task ':stripe:check'

I was trying to build an android apk using Jenkins but I am stuck with one failure message -
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation
processors. Please change the configuration name to 'kapt' for these artifacts:
'com.android.databinding:compiler:3.1.0'.
FAILURE: Build failed with an exception.
What went wrong:
Could not determine the dependencies of task ':stripe:check'.
Task with path 'checkstyle' not found in project ':stripe'.
I have added a third party module stripe in my project and in app level gradle file entry is -
implementation project(':stripe')
I don't know what's wrong is going on build with jenkins is failing all the time.
Note- Below is my stripe's gradle file -
apply plugin: 'com.android.library'
apply plugin: 'checkstyle'
// make sure this line comes *after* you apply the Android plugin
apply plugin: 'com.getkeepsafe.dexcount'
assemble.dependsOn('lint')
check.dependsOn('checkstyle')
You are using kotlin compiler and in kotlin we use "kapt" instead of "annotationProcessor". Check your "Stripe" project and changed gradle accordingly.
After removing below line from stripe's gradle and replacing all the app: 'annotationProcessor' dependencies to kapt , Jenkins is generating build successfully.
check.dependsOn('checkstyle')

Fabric plugin incompatible with Gradle 4.4 +

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?

Kotlin Dokka - Can't find Dokka task in android studio

I am new to Kotlin and Dokka;
Following wikis and tutorials I've tried to setup my project for dokka documentation tool with the following lines in gradle build files:
In project gradle file:
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.15"
In module gradle file:
apply plugin: 'org.jetbrains.dokka-android'
Android studio version is 2.3.3
After Sync, project rebuild and Android studio restart I expected a dokka task appear in "Tools"/"Task & Contexts"/"+ Open Task" but I can't see any.
What am I missing/doing wrong?
Thank you in advance
The dokka task should appear in the Gradle tasks list, check the Gradle panel that's on the right by default:

Mixing android plugins from gradle and gradle-experimental

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"
}

Categories

Resources