Android build gradle dependencies - android

I have an app with 2 libraries as dependencies. I'm trying to build a script that clones those libraries into an empty folder and build the project.
I created a task within the app's build.gradle that clones the repos:
exec { commandLine "git", "clone", repo, repoFolderName }
The script starts and clones the repos, all fine but when it starts building the app if fails with the following error:
"Could not determine the dependencies of task ..."
If I run the script again it will successfully build the project.
From my initial investigation it seems that Gradle creates the dependencies as the 1st thing, before the libraries are locally cloned so the libraries are not there hence the build fails. If I run it again as the libraries are already there it will successfully build the project.
Any help is much appreciated.

Related

Run Ktlint for all modules by executing single task command

I have multiple modules in my android project. I have one Gradle file which having code for ktlint. I applied that Gradle file to every module by writing this in the project Gradle file.
subprojects { subProject ->
apply from: "$project.rootDir/commonFiles/gradleScript/kotlin-code-quality.gradle"
}
now the problem is I can run ktlint on each module by giving their name in command like this.
Running ktlint for cache module.
./gradlew :cache:ktlint
but I need to run all modules ktlint at once.
Here is my open-source repository and pull request on which I need to perform ktlint action.
Sorry, it's my bad. ./gradlew ktlint will always run on multimodule. I had some lint checks fail in the app module. I thought it is running only on the app module.
but when I fixed the app module's lint and ran the ./gradlew ktlint. it jumped to the cache module.
I hope it helps you Thanks.

Android gradle plugin v3.3.0 -> can't find R$raw when using proguard

Just updated to Android gradle plugin version 3.3.0
We have the following setup (not sure which are important):
Application project (app) with 3 library modules (data, domain, utils)
Databinding enabled (databinding.enabled true)
Proguard enabled(proguardFiles 'proguard-rules.pro')
When I build the app using:
./gradlew assembleDevRelease
I get the following error:
can't find referenced class my.package.data.R$raw
When I build the app using:
./gradlew :app:assembleDevRelease
The app builds fine, generates an obfuscated *.apk which I can install
Question:
What's the difference between assembleRelease and :app:assembleRelease
- Why does switching to android gradle plugin 3.3.0 affect which task I have to call to build my apk? We use assembleRelease everywhere in our CI pipelines to build our apks.
What changed in android gradle plugin 3.3.0 that caused the task assembleRelease to break? We use assembleRelease everywhere in our CI pipelines to build our apks.
Any suggestions how we can make 'assembleRelease' working again? (update Proguard config?, enabling R8?)
What's the difference between assembleRelease and :app:assembleRelease
The former runs the assembleRelease task on all modules relative to current level. The latter runs it on the app module only (and its dependencies).
Why does switching to android gradle plugin 3.3.0 affect which task I have to call to build my apk? We use assembleRelease everywhere in our CI pipelines to build our apks.
The question does not have enough info to say for sure, but there are a number of changes listed in the release notes. For example, this issue might be related to:
Faster R class generation for library projects: Previously, the Android Gradle plugin would generate an R.java file for each of your project's dependencies and then compile those R classes alongside your app's other classes. The plugin now generates a JAR containing your app's compiled R class directly, without first building intermediate R.java classes. This optimization may significantly improve build performance for projects that include many library subprojects and dependencies, and improve the indexing speed in Android Studio.

Android aar publish to Artifacotry through TeamCity

Currently we are using TeamCity for continuous integration and I have configured my Android library to build with TeamCity. I can upload my aar to Artifactory manualy by executing gradle assembleRelease artifactoryPublish command.
Is it possible to publish my library aar file to Artifactory repository from the TeamCity?
Assuming you already have builds running on TeamCity:
On TeamCity go to your Project Settings then Build Configurations, Select the build configuration that runs when ever TeamCity runs.
Inside that Build Configuration select Build Step: Gradle, then click the Add Build Step Button.
Select Gradle from the drop down menu.
Give it sensible name e.g. "Publish artifact"
Add your task names in:
Click Save
Then run your TeamCity build like you usually would.
TeamCity runs Gradle tasks. Just use the assembleRelease artifactoryPublish tasks in TeamCity.

Gradle clean task fails for not resolving all dependencies

When I ran ./gradlew clean for my Android project, the task failed for not resolving all dependencies. The complaints came from the gradle task _debugCompile.
I can verify some of the local dependencies didn't exist which failed the dependencies resolving process, but I'm still curious about why the clean task would check for dependencies while not building the project.
Shouldn't it just delete some directories as mentioned in the following link?
https://docs.gradle.org/current/userguide/java_plugin.html#sec:clean
Is there any gradle built-in task that could just clean the build folder without checking dependency?
Thanks!
Gradle already resolves dependencies during its configuration phase which precedes the execution phase, see The Build Lifecycle (it downloads dependencies only once they are needed, though). However, dependencies being out of date does not make resolution fail. If resolution fails that dependency is likely not available online anymore. If you still have the dependency in your Gradle cache you might be able to work around this by specifying the --offline switch:
$ ./gradlew --offline clean

Gradle - Which task creates the 'build' directory?

I'm using Android Studio 1.3.2 on Mac.
Gradle version is listed as 2.2.1, Android Plugin version 1.3.1.
I have applied the FindBugs Gradle plugin, and I've created a task that successfully runs the analysis on the directory 'build/intermediates/classes'.
To trigger this task on Gradle Sync, I've added it as a dependency to the preBuild task, like this:
preBuild.dependsOn findBugs
The problem with this dependency is that, at time of preBuild, the generated class files are either non-existent (first sync) or stale (remaining from previous sync). Basically, I want my task to run immediately after the 'build/intermediates/classes' directory is created, or when the files there are refreshed as part of the 'Sync' operation.
Looking at the tasks available, I can see the 'clean' task has the following description:
clean - Deletes the build directory.
However, none of the other tasks I see describe the directory's creation. My first thought was "Well, it's got to be the build task, right?". Unfortunately, as usual, it's not that simple (pressing gradle 'sync' button, does not trigger my task when I've added it as a dependency to the 'build' task). Is no such task available? If so, which task would best suit what I'm trying to achieve?
You can see all tasks using ./gradlew tasks
The build task is the main one. It builds everything, generates APKs and runs all checks.
I recommend you adding the following to the build.gradle file:
check.dependsOn 'findbugs'
So when you run the check task, it will execute findbugs as well.
Then also set a dependency on findBugs for the compilation task:
task findbugs(type: FindBugs, dependsOn: 'compileDebugSources') {...}
This will compile the source in case you run findbugs without previously compiling it.

Categories

Resources