Disable incremental build for kapt - android

Since android gradle plugin has enabled incremental build by default annotation processing breaks, because only those classes who has been changed since last incremental build will be taken into account from annotation processors.
So for java source code we usually use apt grald plugin to run annotation processing. However, android's gradle plugin automatically disables gradle's incremental build feature if apt is used in the same project:
https://github.com/google/dagger/issues/298
Now I'm working on a kotlin project and Im facing the same incremental build issue with kapt. So the solution, as with apt, is to disable incremental build. The documentation says:
android {
compileOptions.incremental = false
...
}
However, that doesn't work for me. Does anybody know how to disable incremental builds?

You can add
kotlin.incremental=false
to your gradle.properties file to disable the incremental building.

I had the same issue but it seems to be fixed in version 1.0.4. Currently, it's still in the EAP phase so you'll have to add another repository.
repositories {
...
maven { url 'http://dl.bintray.com/kotlin/kotlin-dev' }
}
Then change the version to 1.0.4-eap-xx in your root build.gradle
buildscript {
ext.kotlin_version = '1.0.4-eap-84'
...
}
Here's the link to the issue.

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.

"Injecting the input artifact of a transform as a File has been deprecated."

I'm getting the warning "Injecting the input artifact of a transform as a File has been deprecated. This is scheduled to be removed in Gradle 6.0. Declare the input artifact as a Provider<FileSystemLocation> instead." when Syncing my Gradle.
What in the world does that mean?
I see in the stack trace for the warning something about com.android.build.gradle.internal.dependency.ExtractAarTransform. I do have two dependencies using #aar in my build.gradle:
implementation('com.amazonaws:aws-android-sdk-mobile-client:2.16.8#aar') { transitive = true }
and
implementation 'com.amazonaws:aws-android-sdk-cognitoauth:2.16.8#aar'
Could it be one of these that the warning is referring to? What am I supposed to do with these if not whatever I am doing with them already?
Based On https://kotlinlang.org/docs/reference/kapt.html
Starting from version 1.3.30, kapt supports incremental annotation processing as an experimental feature. Currently, annotation processing can be incremental only if all annotation processors being used are incremental.
Incremental annotation processing is enabled by default starting from version 1.3.50. To disable incremental annotation processing, add this line to your gradle.properties file:
kapt.incremental.apt=false
Incremental compilation
The Kotlin Gradle plugin supports incremental compilation. Incremental compilation tracks changes of source files between builds so only files affected by these changes would be compiled.

Error when executing crashlyticsGenerateSymbols task with android gradle plugin 3.6+

Where do i report this error? or could anyone help me?
“Directory X specified for property ‘$2’ does not exist” error when executing crashlyticsGenerateSymbols task
with
android gradle plugin 3.6.0
gradle version 5.6.4
fabric gradle plugin 1.31.2
[Error logs]
Some problems were found with the configuration of task ':~~~~~:crashlyticsGenerateSymbolsRelease' (type 'DefaultTask').
Directory '~~~' specified for property '$1' does not exist.
Directory '~~~~' specified for property '$2' does not exist.
Fabric/Firebaser here. This error comes up when the Fabric Gradle plugin is trying to parse your project structure in order to find your stripped and unstripped binaries, and is unable to do so. When it asks for properties $1 and $2 it means it could not find the default paths to the "obj" and "libs" folders that contain your supported ABIs folders with your supported native libraries there.
Using the legacy Fabric Gradle plugin, you can specify these paths under your crashlytics block in the build.gradle, like so:
crashlytics {
enableNdk true
androidNdkOut 'obj'
androidNdkLibsOut 'libs'
}
In the case for builds that are on Android Studio 3.5 or later, you can usually find the paths for these somewhere in the outputted build folders under "merged_native_libs" and "stripped_native_libs."
If you're using the new Firebase Crashlytics SDKs and Gradle plugin, those paths are controlled by "strippedNativeLibsDir" and "unstrippedNativeLibsDir" flags in the firebaseCrashlytics block in your build.gradle.
If you continue running into problems feel free to file a case with Firebase support with more details about your project and what you've tried to configure so far, and you can also still reach out to support#fabric.io.
I got the same issue on my side, and I fixed it by removing ext.enableCrashlytics = false from my app-level build.gradle in
android {
buildTypes {
debug {
// ext.enableCrashlytics = false
}
}
}

Android-Gradle: Remote repo+ variant-aware dependency resolution

According to https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html the new Android Gradle Plugin has a variant-aware dependency resolution:
Android plugin 3.0.0 and higher include a new dependency mechanism that automatically matches variants when consuming a library. This means an app's debug variant automatically consumes a library's debug variant, and so on. It also works when using flavors—an app's freeDebug variant will consume a library's freeDebug variant.
But the examples are all written for local project dependencies.
implementation project(':library')
How does this mechanism work for remote dependencies, loaded from a maven repository for example?
implementation 'com.example.android:library:0.0.1'
Furthermore, I figured out two more problems:
How to publish all configurations of an android library together to a maven repository?
At the moment, we are publishing with
publishing {
...
artifact(output.outputFile) {
builtBy variant.assemble
};
pom.withXml {
...
dependencyNode.appendNode('scope', configurationName.contains("mplementation") ? "runtime" : "compile")
...
}
...
}
It seems that the property <scope>runtime</scope> in our *.pom suggested for implementation-dependencies is completely ignored by the android-gradle plugin?
Although, we have a <scope>runtime</scope>, we still can use the classes from the transitive dependent library at compile-time in our project.

Android Gradle Plugin 1.1.0 - getNdkFolder() not found anymore, any replacement?

I just updated android Gradle plugin to 1.1.0 from 1.0.0, and I got this error:
No signature of method:
com.android.build.gradle.LibraryPlugin.getNdkFolder() is applicable
for argument types: () values: []
I tried to find diff of gradle plugin 1.0.0 to 1.1.0 but couldn't find anywhere online.
Seems like getNdkFolder method has been either changed or removed.
Is there a replacement ? Or any other way to get NdkFolder ?
I'm using that method like this,
def ndkDir = project.plugins.findPlugin ( 'com.android.library'
).getNdkFolder ()
I have also filed an issue against tools team in Android issue tracker: https://code.google.com/p/android/issues/detail?id=152810
Thank you !
You can get it like this:
plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
The correct way - android.ndkDirectory
The change from android.plugin.ndkFolder to android.ndkDirectory was documented in the technical doc Migrating Gradle Projects to version 1.0.0. In addition you should update your android plugin to 2.3.0.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}
The sdkFolder is internal and will likely stop working just like ndkFolder stopped working.
Regarding experimental branches
Search around, the plugin is mature enough you'll have trouble finding reasons to use experimental branches with the NDK.
There is some discussion about an Experimental version of the plugin breaking ndkDirectory which is the documented way to access this value after 1.1. If that changes in a released version I'll update my answer, in the mean time if running experimental plugins is your thing you can hack your way around this bug/feature using #Alex Cohn's answer.
I am using gradle 2.2.3 version. The think that worked for me:
def ndkDir = project.android.ndkDirectory
Ref. Link: https://code.google.com/p/android/issues/detail?id=152810
If in the build.gradle file you can probably use this now that the bug referenced has been marked fixed.
project.android.ndkDirectory
If you're in a custom Task or Plugin you'll want to use this
def androidPluginExtension = project.getExtensions().getByName("android");
// Use this for easily viewing the properties available in the extension.
androidPluginExtension.properties.each { Object key, Object value ->
logger.info("Extensionprop: ${key} ${value}")
}
String ndkDir = androidPluginExtension.getProperties().get("ndkDirectory");
System.out.println("Using ndk dir: ${ndkDir}");
But remember that the Android Plugin would have had to have been initialized, so this will always work in a Task's execute method, but it may not work if Gradle hasn't parsed the Android DSL yet during the Gradle Configuration phase.
As Michael Pardo mentioned, you can get it by
*
plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
*
, In case you receive the following error:
Error:(9, 0) Plugin with id com.android.library has not been used.
You can use the applied plugin : 'com.android.application', therefore the final code will be :
def ndkDir = plugins.getPlugin('com.android.application').sdkHandler.ndkFolder

Categories

Resources