java.lang.NoClassDefFoundError: Failed resolution of: Lcom/xxx/xxx/viewmodels/CameraXViewModel; - android

The APK is generated and everything works at compile time but app crash at runtime. The crash is when launching the camera module for barcode scanning implemented with CameraX.
Here is the crash log:
08-22 17:31:16.537 16660-16660/com.xxx.xxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xxx, PID: 16660
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/xxx/xxx/viewmodels/CameraXViewModel;
at com.xxx.xxx.barcode.CameraXLivePreviewActivity.onCreate(CameraXLivePreviewActivity.kt:94)
at android.app.Activity.performCreate(Activity.java:7314)
at android.app.Activity.performCreate(Activity.java:7305)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2948)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3073)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1774)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:7055)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:523)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xxx.xxx.viewmodels.CameraXViewModel" on path: DexPathList[[zip file "/data/app/com.xxx.xxx-LKiFwx0pU2KUfueyYsAm-w==/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx-LKiFwx0pU2KUfueyYsAm-w==/lib/arm64, /data/app/com.xxx.xxx-LKiFwx0pU2KUfueyYsAm-w==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
Here is line 94 where the ViewModel is accessed.
Kindly refer my build details.
Here is the project-level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.xxx.xxx"
minSdk 21
targetSdk 31
versionCode 19
versionName "1.2.13"
multiDexEnabled true
signingConfig signingConfigs.config
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
buildConfigField "String", "AREA", "\"\""
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
buildConfigField "String", "AREA", "\"\""
}
ABC {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
buildConfigField "String", "AREA", "\"_A\""
}
XYZ {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
buildConfigField "String", "AREA", "\"_X\""
}
}
flavorDimensions "appVariant", "projectCode"
productFlavors {
A {
dimension "appVariant"
}
B {
dimension "appVariant"
}
C {
dimension "appVariant"
}
D {
dimension "appVariant"
}
DEV {
dimension "projectCode"
}
QA {
dimension "projectCode"
}
LIVE {
dimension "projectCode"
}
DEMO {
dimension "projectCode"
}
BETA {
dimension "projectCode"
}
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
def project = "TEST_PROJECT"
def SEP = "_"
def flavor = variant.productFlavors[0].name
def projcode = variant.productFlavors[1].name
def buildType = variant.buildType.name
def buildTypeName = "";
switch (buildType) {
case "ABC": buildTypeName = SEP + "AB"; break;
case "XYZ": buildTypeName = SEP + "XY"; break;
default:
buildTypeName = "";
}
def version = variant.versionName
def date = new Date();
def formattedDate = date.format('ddMMyy_HHmm')
def newApkName = project + buildTypeName + SEP + flavor + SEP + projcode + SEP + version + ".apk"
outputFileName = new File(newApkName)
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
dataBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.databinding:databinding-runtime:7.0.2'
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.google.firebase:firebase-messaging-ktx:22.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2'
implementation 'androidx.camera:camera-core:1.0.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Retrofit and GSON
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
//Kotlin Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
//Kodein Dependency Injection
implementation "org.kodein.di:kodein-di-generic-jvm:6.2.1"
implementation "org.kodein.di:kodein-di-framework-android-x:6.2.1"
//Android Room
implementation "androidx.room:room-runtime:2.2.5"
implementation "androidx.room:room-ktx:2.2.5"
kapt "androidx.room:room-compiler:2.2.5"
//Android Navigation Architecture
implementation "androidx.navigation:navigation-fragment-ktx:2.2.0-alpha02"
implementation "androidx.navigation:navigation-ui-ktx:2.2.0-alpha02"
implementation 'com.xwray:groupie:2.8.0'
implementation 'com.xwray:groupie-kotlin-android-extensions:2.8.0'
implementation 'com.xwray:groupie-databinding:2.8.0'
implementation "androidx.preference:preference-ktx:1.1.0"
//Image loading
implementation "com.squareup.picasso:picasso:2.71828"
//barcode
implementation 'com.google.mlkit:barcode-scanning:17.0.0'
// CameraX
implementation "androidx.camera:camera-camera2:1.0.0-SNAPSHOT"
implementation "androidx.camera:camera-lifecycle:1.0.0-SNAPSHOT"
implementation "androidx.camera:camera-view:1.0.0-SNAPSHOT"
// On Device Machine Learnings
implementation "com.google.android.odml:image:1.0.0-beta1"
implementation 'com.google.mlkit:camera:16.0.0-beta1'
implementation 'me.dm7.barcodescanner:zxing:1.9.13'
implementation(files("./libs/scandecode-release.aar"))
implementation 'com.valdesekamdem.library:md-toast:0.9.0'
implementation 'com.tt:whorlviewlibrary:1.0.3'
}
Not sure what is wrong.
Any help will be appreciated.

Solved!.
Implemented multidex from the developer site.
https://developer.android.com/studio/build/multidex
Also there were two view model classes CameraXViewModel & CameraXviewModel.kt, removed the file CameraXviewModel.kt from the project. CameraXViewModel is the one which is used and CameraXviewModel was not referenced any where in the project.
ASFAIK Java and Kotlin is case sensitive for classes, so ideally it should work. Here everything compiled and APK generated but app crashed at runtime.
Hope this helps someone.

Related

Type org.opencv.calib3d.Calib3d is defined multiple times (but only on release, not debug)

In my Android application, I have both imported the OpenCV library, as well as integrated a live edge detection library, which in turn uses OpenCV on its own.
Originally, this created a conflict between the two versions of OpenCV, but I was able to resolve that.
I am now trying to do a production release for the first time since this change, and I am encountering the following error during my release build (in the mergeDex...Release stage):
Type org.opencv.calib3d.Calib3d is defined multiple times: .../OpenCVSDK/build/.transforms/73aaad4d2991f9ad7ec3aa9b43023dc9/transformed/release/org/opencv/calib3d/Calib3d.dex, .../app/build/intermediates/external_libs_dex/prodSbirRelease/mergeExtDexProdSbirRelease/classes3.dex
Why is this suddenly an issue now, with a release build, when it was (and continues to be) fine with debug builds? And how can I fix it?
Here is my app build.gradle:
plugins {
id 'com.android.application'
id 'com.google.android.gms.oss-licenses-plugin'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
signingConfigs {
debug {
storeFile file('.../ReleaseKeyStore')
storePassword '...'
keyAlias 'key0'
keyPassword '...'
}
release {
storeFile file('.../ReleaseKeyStore')
storePassword '...'
keyAlias 'key0'
keyPassword '...'
}
}
compileSdk 31
defaultConfig {
minSdk 26
targetSdk 31
versionCode 3
versionName "0.9.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
// Based on https://www.geeksforgeeks.org/how-to-change-the-default-generated-apk-name-in-android-studio/
// and https://stackoverflow.com/questions/25104323/how-to-customize-the-apk-file-name-for-product-flavors
applicationVariants.all{
variant ->
variant.outputs.each{
output->
def name = "ImageCapture-${variant.flavorName}-${variant.versionName}.apk"
output.outputFileName = name
}
}
}
flavorDimensions "environment", "product"
productFlavors {
local {
dimension "environment"
resValue "string", "app_name", "LOCAL Image Capture"
}
dev {
dimension "environment"
resValue "string", "app_name", "DEV Image Capture"
}
prod {
dimension "environment"
resValue "string", "app_name", "Image Capture"
}
sbir {
dimension "product"
}
nci {
dimension "product"
}
}
androidComponents {
onVariants(selector().all(), { variant ->
switch (variant.name) {
case "localSbirDebug":
case "devSbirDebug":
case "localSbirRelease":
case "devSbirRelease":
variant.applicationId = "ai.dlanalytics.imagecapture.dev"
break
case "prodSbirDebug":
case "prodSbirRelease":
variant.applicationId = "ai.dlanalytics.imagecapture"
break
case "localNciDebug":
case "devNciDebug":
case "localNciRelease":
case "devNciRelease":
variant.applicationId = "ai.dlanalytics.imagecapture.nci.dev"
break
case "prodNciDebug":
case "prodNciRelease":
variant.applicationId = "ai.dlanalytics.imagecapture.nci"
break
}
})
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
pickFirst '**/*.so'
resources {
excludes += ['META-INF/DEPENDENCIES', 'META-INF/LICENSE', 'META-INF/LICENSE.txt', 'META-INF/license.txt', 'META-INF/NOTICE', 'META-INF/NOTICE.txt', 'META-INF/notice.txt', 'META-INF/ASL2.0', 'META-INF/*.kotlin_module']
}
}
buildFeatures {
viewBinding true
mlModelBinding true
}
namespace 'ai.dlanalytics.imagecapture'
}
dependencies {
implementation 'com.github.adityaarora1:LiveEdgeDetection:master-SNAPSHOT'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.activity:activity:1.4.0"
implementation "androidx.fragment:fragment:1.4.1"
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation "com.google.android.gms:play-services-location:19.0.1"
implementation 'com.google.api-client:google-api-client:1.32.2'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation 'com.android.volley:volley:1.2.1'
implementation 'androidx.navigation:navigation-fragment:2.4.2'
implementation 'androidx.navigation:navigation-ui:2.4.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.camera:camera-camera2:1.2.0-alpha01"
implementation "androidx.camera:camera-lifecycle:1.2.0-alpha01"
implementation "androidx.camera:camera-view:1.2.0-alpha01"
implementation "androidx.camera:camera-extensions:1.2.0-alpha01"
implementation "com.github.bumptech.glide:glide:4.11.0"
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
implementation platform('com.google.firebase:firebase-bom:30.0.1')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'
implementation "androidx.work:work-runtime:2.7.1"
implementation project(path: ':OpenCVSDK')
// implementation 'org.bytedeco:opencv:4.5.5-1.5.7'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-ml-modeldownloader'
implementation 'org.tensorflow:tensorflow-lite:2.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
And my project build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url "https://www.jitpack.io" }
google() // Google's Maven repository
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.5'
}
}
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
}
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://www.jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I'm relatively new to Android builds, so please let me know what other helpful information I can provide.

Unable to generate release Build apk

I have a project with this build setting :
Project have separate debug variant
applicationIdSuffix '.debug'
versionNameSuffix '-DEBUG'
On the time of release, there are showing many build variants.
But I'm a beginner developer, so need to sure from you guys, which one is debug build variant that one I need to release?
Then what will do the other build variants?
And this project includes many modules ( like 3rd Party Sample Project )
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
//noinspection GradleDynamicVersion
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven {
url 'some url/'
credentials {
username 'someusername'
password 'somepassword'
}
}
}
// for Crashlytics
apply plugin: 'io.fabric'
// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")
// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()
// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
// applicationVariants.all { variant ->
// //(variant.buildType.name == 'release') {
// variant.mergeAssetsProvider.configure {
// doLast {
// delete(fileTree(dir: outputDir, includes: ['**/*.pdf'])) // '**/js',
// }
// }
// //}
// }
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
lintOptions {
checkReleaseBuilds true
abortOnError true
//warningsAsErrors true
baseline file("lint-baseline.xml")
fatal 'StopShip'
}
compileSdkVersion 28
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.application.sanchyan"
versionName "3.1.8.4"
versionCode 18
targetSdkVersion 28
vectorDrawables.useSupportLibrary = true
renderscriptSupportModeEnabled true
renderscriptTargetApi 19
multiDexEnabled true
}
buildTypes {
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-DEBUG'
//minifyEnabled true
// By using a special debug ProGuard file, you can turn off obfuscation, which would
// otherwise hinder debugging.
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro',
'proguard-rules-debug.pro'
}
release {
minifyEnabled true
//shrinkResources true
signingConfig signingConfigs.release
//multiDexKeepFile file('multidex-config.txt')
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ext.enableCrashlytics = true
//
// IMPORTANT PART:
//
// tell your MultiDex to keep the classes you defined in your Proguard .pro file.
//multiDexKeepProguard file('proguard-rules.pro')
}
}
flavorDimensions "region", "mode", "api"
productFlavors {
// Read these to understand the whole concept better:
// li
// https://proandroiddev.com/advanced-android-flavors-part-1-building-white-label-apps-on-android-ade16af23bcf
// API
pre21 {
dimension "api"
minSdkVersion 19
versionNameSuffix ""
}
post21 {
dimension "api"
minSdkVersion 21
versionNameSuffix ""
}
// MODE
full {
dimension "mode"
}
demo {
dimension "mode"
applicationIdSuffix '.demo'
versionNameSuffix " [Demo]"
}
internal {
dimension "mode"
applicationIdSuffix '.internal'
versionNameSuffix " [Internal]"
}
// REGION
brigon {
dimension "region"
applicationIdSuffix '.brigon'
}
uei {
dimension "region"
applicationIdSuffix '.uei'
}
uk {
dimension "region"
versionNameSuffix ""
}
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation project(':polygonview')
implementation project(':tabbuttonview')
implementation project(':imagetoggleview')
implementation project(':wedgeview')
implementation project(':panzoomview')
implementation project(':flowlayout')
implementation project(':infoview')
implementation project(path: ':utilities')
implementation 'androidx.appcompat:appcompat:1.1.0' // 1.1.0-rc01
/* beta2 causes issues with layouts not showing content till updating (eg DevicePicker) */
//noinspection GradleDependency
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3' // 2.0.0-beta1
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha02' // 1.1.0-alpha09
implementation 'com.google.firebase:firebase-core:17.2.1' // 17.0.0
implementation 'com.google.firebase:firebase-messaging:20.0.1'
implementation 'com.google.firebase:firebase-perf:19.0.2'
implementation 'com.google.maps.android:android-maps-utils:0.6.2'
implementation 'com.pacioianu.david:ink-page-indicator:1.3.0'
implementation 'com.squareup.moshi:moshi:1.9.2'
//noinspection GradleDependency
pre21Implementation 'com.squareup.okhttp3:okhttp:3.14.4'
post21Implementation 'com.squareup.okhttp3:okhttp:4.2.2'
//implementation 'com.squareup.okhttp3:okhttp:3.14.4'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'org.apache.commons:commons-text:1.8'
// for Crashlytics
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.crashlytics.sdk.android:answers:1.4.7'
// for PSPDFKit
implementation 'com.pspdfkit:pspdfkit:6.0.3'
implementation 'androidx.palette:palette:1.0.0'
// for Chrome web content
implementation 'com.android.support:customtabs:28.0.0'
// for image cropping
// implementation 'com.github.yalantis:ucrop:2.2.4-native'
implementation 'com.github.yalantis:ucrop:2.2.4'
// implementation 'com.androidplot:androidplot-core:0.9.4'
// Room components
// implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
// annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
// androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
//annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
implementation "android.arch.lifecycle:common-java8:1.1.1"
testImplementation 'junit:junit:4.13-rc-2'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
//noinspection GradlePath
implementation files('C:/Users/Dell/Documents/ProjectFilePath/libs/YouTubeAndroidPlayerApi.jar')
}
apply plugin: 'com.google.gms.google-services'
And the error shows on release build time is
Missing org.conscrypt.ConscryptHostnameVerifer
I don't know how much future error will come to release.
Please help me out
read this topic
And this one
While reading the info message, it gives me an idea about this Conscrypt and did a research and found out that I need to install conscrypt to my gradle.app
implementation 'org.conscrypt:conscrypt-android:2.2.1'
and it works.

App version shows as 0.0(0) after uploading to Fabric Beta

I'm manually uploading the build in Crashlytics Beta. But the version number always shows as 0.0(0) like mentioned in this post. (Please don't mark as duplicate as this is a bit different as this occurs even with manual upload) I'm using Android Studio 3.1.3. and Gradle version 4.4
Here's my gradle :
classpath 'io.fabric.tools:gradle:1.+'
compile('com.crashlytics.sdk.android:crashlytics:2.9.1#aar') {
transitive = true;
}
Complete app/build.gradle :
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.3'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'io.fabric'
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url 'http://kochava.bintray.com/maven' }
}
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
flavorDimensions "default"
useLibrary 'org.apache.http.legacy'
dexOptions {
preDexLibraries true
javaMaxHeapSize "2g" // Use gig increments depending on needs
}
lintOptions {
abortOnError false
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
repositories {
flatDir { dirs 'libs' }
}
signingConfigs {
debugConfig {
storeFile file('keystore/debug.keystore')
storePassword "/*password*/"
keyAlias "androiddebugkey"
keyPassword "/*password*/"
}
releaseConfig {
storeFile file("keystore/release.keystore")
storePassword "/*password*/"
keyAlias "/*KeyAliasname*/"
keyPassword "/*password*/"
}
}
// Versioning
def versionPropsFile = file('version.properties')
def versionBuild
/*Setting default value for versionBuild which is the last incremented value stored in the file */
if (versionPropsFile.canRead()) {
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
versionBuild = versionProps['VERSION_BUILD'].toInteger()
} else {
throw new GradleException("Could not read version.properties!")
}
/*Wrapping inside a method avoids auto incrementing on every gradle task run. Now it runs only when we build apk*/
ext.autoIncrementBuildNumber = {
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(file("version.properties").newReader()/*new FileInputStream(versionPropsFile)*/)
versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
versionProps['VERSION_BUILD'] = versionBuild.toString()
versionProps.store(versionPropsFile.newWriter(), null)
} else {
throw new GradleException("Could not read version.properties!")
}
}
def appId = "com.example.appName"
def appName = "My App"
def appBuildName = "appBuildName"
def versionMajor = 6
def versionMinor = 6
def versionPatch = 0
def appVersionName = "${versionMajor}.${versionMinor}.${versionPatch}"
def appVersionCode = versionBuild
defaultConfig {
applicationId appId
minSdkVersion 16
targetSdkVersion 27
resValue "bool", "is_prod", "false"
resValue "bool", "is_prod_staging", "false"
resValue "bool", "is_amazon", "false"
// by default, enable logging
resValue "bool", "is_debuggable", "true"
multiDexEnabled = true
}
buildTypes {
applicationVariants.all { variant ->
variant.outputs.all { output ->
def project = appBuildName
def SEP = "-"
def buildType = variant.variantData.variantConfiguration.buildType.name.toUpperCase()
def flavor = variant.productFlavors[0].name.toUpperCase()
def version = "v" + appVersionName + "." + (appVersionCode - 500000)
def newApkName = project + SEP + version + SEP + buildType + SEP + flavor + ".apk"
println "Output Apk Name: " + newApkName
outputFileName = new File(newApkName)
}
}
debug {
applicationIdSuffix ".debug"
ext.enableCrashlytics = false
}
uat {
initWith(buildTypes.debug)
applicationIdSuffix ".uat"
signingConfig signingConfigs.debugConfig
ext.enableCrashlytics = true
}
staging {
applicationIdSuffix ".uat"
signingConfig signingConfigs.debugConfig
debuggable false
// we want the prod endpoint, with no logging
resValue "bool", "is_prod_staging", "true"
resValue "bool", "is_debuggable", "false"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ext.enableCrashlytics = true
}
prodStaging {
initWith(buildTypes.staging)
resValue "bool", "is_prod_staging", "false"
resValue "bool", "is_prod", "true"
}
prodStagingNoSuffix {
initWith(buildTypes.prodStaging)
applicationIdSuffix ""
debuggable false
}
release {
// we want the prod endpoint, with no logging
resValue "bool", "is_prod", "true"
resValue "bool", "is_debuggable", "false"
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseConfig
ext.enableCrashlytics = true
}
}
productFlavors {
play {
resValue "bool", "is_amazon", "false"
}
amazon {
resValue "bool", "is_amazon", "true"
}
}
// Hook to check if the release/debug task is among the tasks to be executed.
//Let's make use of it
gradle.taskGraph.whenReady { taskGraph ->
def tasks = taskGraph.getAllTasks()
tasks.find {
println it
if (it.name.toLowerCase().contains("package")
&& !it.name.toLowerCase().contains("debug")
&& !it.name.toLowerCase().contains("release")) {
/* when run release task */
/* note that the task cannot be a release as our release codes need to align */
println("We've matches on the internal release task")
autoIncrementBuildNumber()
return true
}
return false
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'com/kofax/android/abc/configuraPK'
exclude 'META-INF/rxjava.properties'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1#aar') {
transitive = true;
}
// Apache 2.0
implementation files('libs/adobeMobileLibrary-4.13.2.jar')
implementation files('libs/dagger-2.7.jar')
implementation files('libs/isg-3.2.0.0.0.761.jar')
implementation files('libs/sdk-release.jar')
implementation files('libs/login-with-amazon-sdk.jar')
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.facebook.android:facebook-android-sdk:4.27.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-gcm:15.0.1'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
implementation 'com.squareup:otto:1.3.6'
implementation 'commons-io:commons-io:2.4'
implementation 'commons-codec:commons-codec:1.10'
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'org.roboguice:roboguice:3.0.1'
implementation 'com.novoda:accessibilitools:1.3.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'me.relex:circleindicator:1.2.2#aar'
implementation 'com.kochava.base:tracker:3.0.0#aar'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation project(path: ':linkedin-sdk', configuration: 'default')
implementation 'com.squareup.picasso:picasso:2.5.2'
//rxjava
implementation 'io.reactivex.rxjava2:rxjava:2.1.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
//room
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
implementation 'android.arch.persistence.room:rxjava2:1.1.1'
//gson
implementation 'com.google.code.gson:gson:2.3.1'
//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
Note : It used to work fine with Android Studio 2.2

Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:

I am not able to build release APK. Every time I get DexMergerException.
Here are my build.gradles:
I am using MVVM structure. I have core(package name for core is same as my app package) has my lib where I only write view models, models and network layers.
Errors I am getting:
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Caused by: com.android.tools.r8.utils.AbortException
Program type already present:
app build.gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
signingConfigs {
debug {
storeFile file(DEBUG_STORE_FILE)
}
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
v2SigningEnabled false
}
}
compileSdkVersion 27
flavorDimensions "default"
defaultConfig {
applicationId "com.puma.one8crew"
minSdkVersion 21
targetSdkVersion 27
vectorDrawables.useSupportLibrary = true
versionCode 1
multiDexEnabled true
versionName "1.0"
resValue 'string', 'facebook_app_id', FACEBOOK_APP_ID_DEV
resValue 'string', 'fb_login_protocol_scheme', FACEBOOK_LOGIN_PROTOCOL_SCHEME
manifestPlaceholders += [
FACEBOOK_APP_ID_BGY: FACEBOOK_APP_ID_DEV,
FB_LOGIN_SCHEME : FACEBOOK_LOGIN_PROTOCOL_SCHEME
]
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
buildTypes {
debug {
minifyEnabled false
signingConfig signingConfigs.debug
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
/* productFlavors {
prod {
resValue 'string', 'facebook_app_id', FACEBOOK_APP_ID_DEV
resValue 'string', 'fb_login_protocol_scheme', FACEBOOK_LOGIN_PROTOCOL_SCHEME
}
stage {
resValue 'string', 'facebook_app_id', FACEBOOK_APP_ID_DEV
resValue 'string', 'fb_login_protocol_scheme', FACEBOOK_LOGIN_PROTOCOL_SCHEME
}
}*/
applicationVariants.all { variant ->
variant.outputs.all { output ->
def project = "one8crew"
outputFileName = "${project}_${variant.buildType.name}_${variant.versionName}.apk"
}
}
dexOptions {
javaMaxHeapSize "4g" //specify the heap size for the dex process
preDexLibraries = true //delete the already predexed libraries
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':core')
implementation 'com.android.support:animated-vector-drawable:27.0.1'
implementation 'com.android.support:customtabs:27.0.1'
implementation 'com.android.support:cardview-v7:27.0.1'
implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.facebook.android:facebook-android-sdk:4.31.0'
implementation 'com.android.support:recyclerview-v7:27.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.android.support:support-v4:27.0.1'
implementation 'com.android.support:design:27.0.1'
implementation 'com.android.support:support-v13:27.0.1'
implementation 'com.alimuzaffar.lib:pinentryedittext:1.3.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//Dependencies for LifeCycle Android ViewModel
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation project(':com.wowza.gocoder.sdk')
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
//support design lib dependency fot tab
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1#aar') {
transitive = true;
}
}
Below is my core build.gradle and I have also updated the same version for all lib.
core build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
repositories {
flatDir {
dirs 'libs'
}
jcenter()
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
compileOnly 'com.wowza.gocoder.sdk.android:com.wowza.gocoder.sdk:1.0b7#aar'
// compile 'android.arch.lifecycle:extensions:1.1.1'
implementation 'com.google.dagger:dagger:2.11'
api('com.squareup.retrofit2:retrofit:2.1.0') {
exclude module: 'okhttp'
}
api 'com.google.code.gson:gson:2.8.1'
api 'com.squareup.retrofit2:converter-gson:2.3.0'
api 'swarajsaaj:otpreader:1.1'
api 'com.github.bumptech.glide:glide:4.3.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
//Dependencies for LifeCycle Android ViewModel
implementation 'android.arch.lifecycle:extensions:1.1.1'
// annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
compileOnly project(':com.wowza.gocoder.sdk')
compile project(':libraries:horizontalcalendar')
compile project(':libraries:calendarview')
//Library for setting fonts
api 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.android.support:multidex:1.0.3'
}
I tried so many time and I am not able to understand the reason behind this issue.
Same happened today to me and this is what solved the issue:
Find all the dependencies of com.google.android.gms:play-services.
They all have now different versions. Just place the mouse over them and correct the version numbers (i.e. for me was upgrading maps from 15.0.0 to 15.0.2 and tag-manager to 15.0.1)

compile gradle task is always executed

I have a multidex project with minSDK 21, using gradle 4.5.1 and gradle plugin 3.0.1. My issue is that even without any source file change when I try to assemble and deploy to a phone the compile task is executed. When running with --info I get the following reasons:
Task ':app:compileStandardDebugJavaWithJavac' is not up-to-date because:
Input property 'source' file C:...\app\build\generated\source\buildConfig\standard\debug[package]\BuildConfig.java has changed.
Input property 'source' file C:...\app\build\generated\source\dataBinding\standard\debug\android\databinding\layouts\DataBindingInfo.java has changed.
Can you help my identify what could cause these files to change and causes a recompile? I believe the Databinding sources either shouldn't change without changing sources, or it shouldn't affect if the compile task is up-to-date. The same goes for BuildConfig.java.
I have gradle caching, configure on demand and daemon enabled.
Here's the app build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 21
targetSdkVersion 25
applicationId 'package'
// for automated testing
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
buildConfigField "boolean", "PUBLIC_RELEASE", 'false'
}
dataBinding {
enabled true
}
lintOptions {
abortOnError false
}
flavorDimensions "tier1"
productFlavors {
standard {
resValue "string", "app_name", "myapp"
dimension "tier1"
}
beta {
applicationId 'package.beta'
resValue "string", "app_name", "myapp2"
dimension "tier1"
}
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
def project = "myapp"
def separator = "-"
def flavor = variant.productFlavors[0].name
def buildType = variant.variantData.variantConfiguration.buildType.name
def newApkName = project + separator + flavor + separator + buildType + ".apk"
outputFileName = newApkName
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
beta {
aidl.srcDirs = ['src/standard/aidl']
java.srcDirs = ['src/standard/java']
}
}
signingConfigs {
buildTypes {
debug {
buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
}
release {
buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug_StandardAndBeta
debuggable true
buildConfigField "boolean", "CallLogEnabled", "true"
minifyEnabled false
}
release {
signingConfig signingConfigs.release_StandardAndBeta
debuggable false //set to true for custom debugable release build
buildConfigField "boolean", "CallLogEnabled", "false"
minifyEnabled true //set to false for custom debugable release build
proguardFiles 'proguard.cfg'
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
disable "NewApi", "RtlCompat", "MissingPermission", "InvalidPackage", "RecyclerView"
abortOnError false
}
}
repositories {
flatDir {
dirs 'libs'
}
// Crashlytics
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// - Google APIs
implementation('com.google.api-client:google-api-client-android:1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.apis:google-api-services-gmail:v1-rev53-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation 'net.openid:appauth:0.4.1'
implementation 'com.microsoft.graph:msgraph-sdk-android:1.1.+'
implementation 'net.hockeyapp.android:HockeySDK:4.1.1'
// DB framework
implementation 'com.j256.ormlite:ormlite-android:4.48'
// RX Java
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.1.6'
// HTTP frameworks
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
// Google Adwords Tracking
implementation files('libs/Google/GoogleConversionTrackingSdk-2.2.4.jar')
// GMS
implementation 'com.google.android.gms:play-services-analytics:9.0.2'
implementation 'com.google.android.gms:play-services-gcm:9.0.2'
implementation 'com.google.android.gms:play-services-identity:9.0.2'
implementation 'com.google.android.gms:play-services-ads:9.0.2'
implementation 'com.google.android.gms:play-services-auth:9.0.2'
// Other dependencies
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:preference-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.google.code.gson:gson:2.8.+'
implementation 'com.github.clans:fab:1.6.+'
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
implementation 'com.caverock:androidsvg:1.2.2-beta-1'
implementation 'de.greenrobot:eventbus:2.4.1'
implementation 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
implementation 'com.facebook.device.yearclass:yearclass:1.0.+'
implementation 'com.facebook.android:facebook-android-sdk:4.15.0'
implementation 'org.parceler:parceler-api:1.1.9'
annotationProcessor 'org.parceler:parceler:1.1.9'
// Android architecture components
implementation "android.arch.lifecycle:extensions:1.0.0"
}
It's because you're using a buildConfigField with System.currentTimeMillis(). This line causes the BuildConfig class to be updated for debug builds:
buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
The Android Gradle Plugin updates the BuildConfig.java everytime you do a build and inserts the current Date, producing a static field similar to this one:
public static final java.util.Date buildTime = new java.util.Date(1518194256644L);
and since the time changes all the time (haha), the file has to be recompiled.
In my case, the problem was that I was appending date to version name.
def static getDate() {
return new Date().format('yyyyMMddHHmmss')
}
buildTypes {
debug {
// REMOVE THIS LINE
versionNameSuffix '-' + getDate()
applicationIdSuffix ".test"
}
The line in question was
versionNameSuffix '-' + getDate()
In case anyone else encounters the same problem.

Categories

Resources