Force Gradle build to fail when releasing with SNAPSHOT dependencies - android

I would like to prevent the usage of SNAPSHOT dependencies when building with Gradle a release version of an Android application or library.
How can I force the Gradle build to fail if there are any SNAPSHOT dependencies when building the release?

You could use a ResolutionStrategy.
See here for the API:
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
The below example was posted in the Gradle forums by Peter_Niederwieser
https://discuss.gradle.org/t/enforce-no-snapshot-dependencies-in-gradle/3851/2
configurations.all {
if (isRelease) {
resolutionStrategy.eachDependency { details ->
if (details.requested.version.endsWith("-SNAPSHOT")) {
throw new GradleException("found snapshot dependency")
}
}
}
}
The code must be placed either in the module build.gradle or in the "allprojects" section of the main build.gradle.

Related

Crashlytics doesn't display native crashes

Before this gets marked as a duplicate, I have tried everything from all the possible questions.
Java crashes are reported properly, however crashes from the native libs don't have the debug symbols.
What i've tried:
./gradlew crashlyticsUploadSymbolsDevDebug // to upload the symbols manually
androidNdkOut 'build/intermediates/ndkBuild/devDebug/obj/local' //specify the ndk paths manually
androidNdkLibsOut 'build/intermediates/merged_native_libs/devDebug/out/lib'` //specify the ndk paths manually
The current setup:
Dependencies:
implementation('com.crashlytics.sdk.android:crashlytics:2.10.1#aar') { transitive = true }
implementation 'com.crashlytics.sdk.android:crashlytics-ndk:2.1.1'
android.applicationVariants.all { variant ->
def variantName = variant.name.capitalize()
def task = task("ndkbuild${variantName}")
task.finalizedBy("crashlyticsUploadSymbols${variantName}")
}
crashlytics {
enableNdk true
manifestPath 'AndroidManifest.xml'
androidNdkOut 'build/intermediates/ndkBuild/devDebug/obj/local'
androidNdkLibsOut 'build/intermediates/merged_native_libs/devDebug/out/lib'
}
The fabric dependencies:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
Fabric is setup and working with the Java layer crashes.
Fabric.Builder builder = new Fabric.Builder(this).kits(new Crashlytics(), new
CrashlyticsNdk());`
The problem: Native crashes get reported but the debug symbols are missing, there are no error/outputs that indicate why they're missing.
I made a sample app in order to be able to reproduce this more easily.
All you have to do is create a project in firebase and paste the google-services.json file and build.
Link to the repo
This might be caused by debug symbols in another module or because of an outdated configuration.
Try to configure it alike this:
crashlytics {
enableNdk true
// If using the Android plugin for Gradle version 2.2.0+ with the externalNativeBuild DSL,
// you should remove the androidNdkOut and androidNdkLibsOut properties, as these paths will
// automatically be detected by the Fabric plugin.
androidNdkOut 'obj'
androidNdkLibsOut 'libs'
manifestPath 'AndroidManifest.xml'
}
However, you should better migrate to Firebase Crashlytics, because Fabric will shut it down soon:
Crashlytics has been integrated into Firebase, with new Firebase-only features. New apps should use Crashlytics in Firebase to get access to the latest updates and features. Fabric Crashlytics and the Fabric dashboard will be available until March 31, 2020 for existing users.

Could not determine the dependencies of task ':app:dokka'

I'm trying to use dokka on my android project to generate kdoc.
But I have this error when I'm running the script 'modules:app [dokka]' :
Could not determine the dependencies of task ':app:dokka'.
kotlin.KotlinNullPointerException (no error message)
I added the following lines on my gradle files :
Project build.gradle
buildscript {
ext {
dokka_version = '0.9.18'
}
dependencies {
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
}
}
app build.gradle
plugins {
id 'org.jetbrains.dokka-android'
}
dokka {
outputFormat = 'html'
sourceDirs = files('src/main')
outputDirectory = "$buildDir/javadoc"
}
Could not determine the dependencies of task ':app:dokka'.
kotlin.KotlinNullPointerException (no error message)
The issue is that it's a multiplatform project. In the app level gradle file, I'm also applying the org.jetbrains.kotlin.multiplatform plugin. As described in the dokka github release page:
Experimental Kotlin Multiplatform support is scheduled for 0.9.19
Looks like there's no other solution than wait for the next release of dokka.
Edit: There's a workaround described on the kolinlang forum
dokka {
impliedPlatforms = ["common"] // This will force platform tags for all non-common sources e.g. "JVM"
kotlinTasks {
// dokka fails to retrieve sources from MPP-tasks so they must be set empty to avoid exception
// use sourceRoot instead (see below)
[]
}
sourceRoot {
// assuming there is only a single source dir...
path = kotlin.sourceSets.commonMain.kotlin.srcDirs[0]
platforms = ["common"]
}
}

Error: Conflict with dependency 'com.android.support:multidex' in project

I created a new android project with the following gradle file:
android {
...
dexOptions {
javaMaxHeapSize "4g"
}
...
}
dependencies {
...
compile 'com.linkedin.dexmaker:dexmaker-mockito:2.16.0'
...
}
But when I build my app I get:
Conflict with dependency 'com.android.support:multidex' in project
':app'. Resolved versions for app (1.0.3) and test app (1.0.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details.
How can I solve this issue?
The error says you are using 2 versions of com.android.support:multidex.Check this
https://stackoverflow.com/a/37357786/3111083 So in your case it should be
android {
configurations.all {
resolutionStrategy.force 'com.android.support:multidex:1.0.3'
}
}
After changing this Clean and rebuild.
Mockito depends only on a specific version, so the dependency conflict should be on your side. Do you have any dependencies that depend on specific version? i.e.in your build.gradle file. If so, you can try using a ResolutionStrategy to force 1.0.3 on them.

How can I get the current flavor while looping dependencies in android gradle?

We've got a huge project with 100s of flavors. To help keep our Google play services in line I'd like to define a default version and then override it in flavors as needed.
So to for all our various dependencies to use the same version I've got this:
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
//specifying a fixed version for all libraries with 'com.google.android.gms' group
if (details.requested.group == 'com.google.android.gms') {
details.useVersion '8.4.0'
}
}
}
}
I'd like to define:
defaultConfig {
ext.googlePlayServicesVersion '9.6.0'
}
then over ride it in my flavor:
myFlavor {
// XXX plugin requires this older version
ext.googlePlayServicesVersion '8.4.0'
}
Then use the variable version in the configuration.all loop.
Is there anyway to access that variable in the that loop?
You can do this directly in your dependencies block:
dependencies {
compile "com.google.android.gms:play-services-ads:$ext.googlePlayServicesVersion"
myFlavorCompile "com.google.android.gms:play-services-ads:$ext.googlePlayServicesVersionOld"
}
Any project flavor dependencies set with flavorNameCompile will override the default compile dependency for the same dependency and allow you to override the version for specific flavors.
(I use play-services-ads only as an example)

Gradle: compiling SNAPSHOT library

I have this library I want to use, I can install one version, but the developer released a recent SNAPSHOT version, how can I compile it?
I've tried compile 'com.(...):1.4.0-SNAPSHOT without results?
Since SNAPSHOT is a Maven concept, it isn't treated as anything special in repository.
The best way to tell Gradle to check for updated version of a dependency is to flag the dependency as changing. Gradle will then check for updates every 24 hours, this can be configured using the resolutionStrategy DSL.
Override default module caching in Gradle:
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
Then, latest.integration will work with each SNAPSHOT:
dependencies {
compile ('projGroup:projName:latest.integration') { changing = true }
}
For example in your case, projGroup is com.prolificinteractive and projName is material-calendarview.
dependencies {
compile('com.prolificinteractive:material-calendarview:1.4.0-SNAPSHOT') { changing = true }
}
Edit:
Another problem is that bringing latest release on the central repository defined, this repository actually not contain the SNAPSHOT repository where the -SNAPSHOT was located. So that you should add to your gradle repositories section the repository URL to allow download the SNAPSHOT version uploaded.
repositories {
mavenCentral()
mavenLocal()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}

Categories

Resources