Integrating Crashlytics in a multi-module project - android

I have an Android project with a main module plus multiple other sub-modules. I integrated Crashlytics in the project successfully, by updating the project-level build.gradle and the main module build.gradle:
Project-level gradle:
buildscript {
repositories {
jcenter()
maven {url 'https://maven.google.com'}
maven {url 'https://maven.fabric.io/public'}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
allprojects {
repositories {
jcenter()
google()
maven {url 'https://maven.fabric.io/public'}
}
}
Main-module build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
android {
...
}
dependencies {
implementation ('com.crashlytics.sdk.android:crashlytics:2.10.1') {
transitive = true;
}
...
implementation project(':modules:sensordata:collection:ambient:module-wifinetwork')
...
}
repositories {
maven { url 'https://dl.bintray.com/rvalerio/maven' }
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
jcenter()
}
build.gradle for module module-wifinetwork (similar for every module):
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility = 1.8
sourceCompatibility = 1.8
}
}
dependencies {
implementation ('com.crashlytics.sdk.android:crashlytics:2.10.1') {
transitive = true;
}
...
}
My problem is that crash reports from the main-module are correctly sent to the firebase backend, while crash reports in other modules are not, even though they are correctly identified, because if I put this command in a class in the sub-module:
Crashlytics.getInstance().crash();
I receive the following:
2019-12-18 10:19:54.328 29944-30002/it.unitn.disi.witmee.sensorlog E/EventBus: Could not dispatch event: class it.unitn.disi.witmee.modules.core.systembus.model.BusObject to subscribing class class it.unitn.disi.witmee.modules.core.systembus.core.SensorlogMainBus
java.lang.ArrayIndexOutOfBoundsException: length=2; index=10
at com.crashlytics.android.core.CrashTest.indexOutOfBounds(CrashTest.java:30)
at com.crashlytics.android.core.CrashlyticsCore.crash(CrashlyticsCore.java:635)
at com.crashlytics.android.Crashlytics.crash(Crashlytics.java:340)
at it.unitn.disi.witmee.modules.sensordatacollection.ambient.wifinetwork.runnables.SensorRunnable.run(SensorRunnable.java:38)
at it.unitn.disi.witmee.modules.sensordatacollection.sensormodule.receivers.StartAllBroadcastReceiver.busEventCallback(StartAllBroadcastReceiver.java:23)
at it.unitn.disi.witmee.modules.core.systembus.core.SensorlogMainBus.onEvent(SensorlogMainBus.java:219)
at java.lang.reflect.Method.invoke(Native Method)
at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:507)
at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:501)
at org.greenrobot.eventbus.BackgroundPoster.run(BackgroundPoster.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Any clue why this is not working in the sub-module? Thank you

I found the issue, just had to rebuild the project. So the solution is to add the following elements to the project-level build.gradle and to the main-module build.gradle, nothing to be added to individual modules build.gradle. And then clean and rebuild your project.
Project-level build.gradle:
buildscript {
repositories {
...
maven {url 'https://maven.fabric.io/public'}
...
}
dependencies {
...
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
allprojects {
repositories {
...
maven {url 'https://maven.fabric.io/public'}
}
}
Main-module build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
android {
...
}
dependencies {
implementation ('com.crashlytics.sdk.android:crashlytics:2.10.1') {
transitive = true;
}
...
repositories {
...
}

Related

Android: Failed to resolve: com.github.vpotvin:caldroidx:1.0

I am trying to integrate the CaldroidX library in my app (https://github.com/vpotvin/CaldroidX). However, I receive the below error:
Failed to resolve: com.github.vpotvin:caldroidx:1.0
This seems strange, as I believe I have followed the instructions correctly:
Specified maven { url 'https://jitpack.io' } in the project-level build.gradle.
Specified implementation 'com.github.vpotvin:caldroidx:1.0' in the app-level build.gradle.
Below is my project-level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Below is my app-level build.gradle:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.hijriconversioncalendar"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.github.vpotvin:caldroidx:1.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
You have added the maven repository at wrong place, change your project level gradle file like,
// Top-level build file where you can add configuration options common to all
sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

NoClassDefFoundError for web3j.httpClient

I've programmed an android library which uses the org.web3j:core:4.6.0-android dependency. Now I've exported my library as a .aar and imported as a new module into a android application. I can build and run the application but as soon as a function uses the web3j:httpClient it throw the exception: NoClassDefFoundError for web3j.httpClient...
How can I solve this issue?
This is my build-gradle of my application, the example_sdk part is my android library using web3j:
group 'io.test.test_plugin'
version '1.0'
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
rootProject.allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'java/libs'
}
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 19
}
lintOptions {
disable 'InvalidPackage'
}
}
dependencies {
implementation project(path: ':example-sdk')
implementation "androidx.core:core-ktx:+"
}
repositories {
mavenCentral()
}

BillingClient and PurchasesUpdateListener classes not available

I'm trying to add in-app billing as described here:
https://developer.android.com/google/play/billing/integrate
and think I have set up dependencies as instructed, but still, both the BillingClient and PurchasesUpdateListener classes as in the code example on the page are not available.
My project's build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '29.0.2'
defaultConfig {
applicationId "com.myproject"
minSdkVersion 17
targetSdkVersion 26
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android {
useLibrary 'org.apache.http.legacy'
}
dependencies {
implementation 'com.google.android.gms:play-services-ads:19.5.0'
implementation 'com.android.billingclient:billing:3.0.1'
}
My top-level build.gradle:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
How to fix this?
Changing my global build.gradle as follows helped me to resolve the missing dependencies:
buildscript {
repositories {
jcenter()
google()
mavenLocal()
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "http://oss.sonatype.org/content/repositories/releases/" }
maven { url "https://maven.springframework.org/release" }
maven { url "https://maven.restlet.com" }
maven { url "https://jcenter.bintray.com" }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
Hopefully this helps someone.
Make sure the global build.gradle is using the latest versions.
Then resyncing will resolve all the issues.

Cannot add task ':app:reportSourceSetTransformTest' as a task with that name already exists

Minimum supported gradle version 4.6 Current version is 4.4.
After updating gradle version to 4.6, am getting this error
Cannot add task ':app:reportSourceSetTransformTest' as a task with that name already exists.
How can I avoid this error. It seems like two different files have same task. But I didnot find any or explicitly define any task in my app level build.gradle file.
My project level build.gradle file is this:
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and app level build.gradle file is this:
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 27
buildToolsVersion '27.0.1'
flavorDimensions "default"
defaultConfig {
applicationId "com.applicationId"
minSdkVersion 16
targetSdkVersion 27
versionCode 3
versionName "1.0.2"
vectorDrawables.useSupportLibrary = true
}
aaptOptions {
cruncherEnabled = false
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {
implementation project(':demo')
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
androidTestImplementation('junit:junit:4.12')
implementation 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'
}
In my case I had a conflict with my flavour name and new gradle plugin.
The problem was solved when I changed the names of my flavours (Production, Test) -> (production, develop)

android can't add one singnal

I am trying to one signal to my project and i add dependencies like this
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.8.1'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
and in my build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.2.1'
classpath 'io.fabric.tools:gradle:1.24.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'http://jhoobin.abroid.com/repo/' }
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
google()
}
}
but i keep getting error when i sync the gradle
Error:Unable to resolve dependency for ':app#debug/compileClasspath': Could not find any version that matches com.google.android.gms:play-services:15.+.
Open FileShow Details
what is wrong with my code ?
These are my gradles.
This is my :app gradle
//noinspection GradleCompatible
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.app.app"
manifestPlaceholders = [onesignal_app_id: "APP_ID_HERE",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "PROJECT_NUMBER_HERE"]
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/commons-io-2.4.jar')
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.onesignal:OneSignal:3.+#aar'
// Required for OneSignal, even if you have added FCM.
compile 'com.google.android.gms:play-services-gcm:10.2.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
My main projects gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Categories

Resources