transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.65k stars 425 forks source link

java.lang.NoClassDefFoundError: com.transistorsoft.locationmanager.adapter.TSConfig #2012

Closed vksgautam1986 closed 6 months ago

vksgautam1986 commented 6 months ago

app is working fine but issue comes after i added the bugsnag 7.21.0 plugin in app , my app gets crash after few minutes but logs shows the transistorsoft issue . If i remove this bugsnag plugin app gets work fine again.

Your Environment

import com.android.build.OutputFile import org.apache.tools.ant.taskdefs.condition.Os

/**

project.ext.react = [ enableHermes: false, // clean and rebuild if changing ]

apply from: "../../node_modules/react-native/react.gradle" apply plugin: "com.bugsnag.android.gradle"

Project background_geolocation = project(':react-native-background-geolocation') apply from: "${background_geolocation.projectDir}/app.gradle"

/**

/**

def enableShrinkResource = true

/**

/**

/**

android { ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
    applicationId "com.caresmartz360.pro"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 73
    versionName '2.42'
    buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
   ndk {
    debugSymbolLevel 'FULL'
}

    if (isNewArchitectureEnabled()) {
        // We configure the NDK build only if you decide to opt-in for the New Architecture.
        externalNativeBuild {
            ndkBuild {
                arguments "APP_PLATFORM=android-21",
                    "APP_STL=c++_shared",
                    "NDK_TOOLCHAIN_VERSION=clang",
                    "GENERATED_SRC_DIR=$buildDir/generated/source",
                    "PROJECT_BUILD_DIR=$buildDir",
                    "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
                    "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
                cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
                cppFlags "-std=c++17"
                // Make sure this target name is the same you specify inside the
                // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
                targets "caresmartz360_appmodules"
                // Fix for windows limit on number of character in file paths and in command lines
                if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                    arguments "NDK_APP_SHORT_COMMANDS=true"
                }
            }
        }
        if (!enableSeparateBuildPerCPUArchitecture) {
            ndk {
                abiFilters (*reactNativeArchitectures())
            }
        }
    }
    // Added for react-native-image-crop-picker
    vectorDrawables.useSupportLibrary = true
    missingDimensionStrategy 'react-native-camera', 'general' 
    multiDexEnabled true
}

if (isNewArchitectureEnabled()) {
    // We configure the NDK build only if you decide to opt-in for the New Architecture.
    externalNativeBuild {
        ndkBuild {
            path "$projectDir/src/main/jni/Android.mk"
        }
    }
    def reactAndroidProjectDir = project(':ReactAndroid').projectDir
    def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
        dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
        from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
        into("$buildDir/react-ndk/exported")
    }
    def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
        dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
        from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
        into("$buildDir/react-ndk/exported")
    }
    afterEvaluate {
        // If you wish to add a custom TurboModule or component locally,
        // you should uncomment this line.
        // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
        preDebugBuild.dependsOn(packageReactNdkDebugLibs)
        preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)

        // Due to a bug inside AGP, we have to explicitly set a dependency
        // between configureNdkBuild* tasks and the preBuild tasks.
        // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
        configureNdkBuildRelease.dependsOn(preReleaseBuild)
        configureNdkBuildDebug.dependsOn(preDebugBuild)
        reactNativeArchitectures().each { architecture ->
            tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
                dependsOn("preDebugBuild")
            }
            tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
                dependsOn("preReleaseBuild")
            }
        }
    }
}

splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include (*reactNativeArchitectures())
        include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
    release {
        if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
            storeFile file(MYAPP_UPLOAD_STORE_FILE)
            storePassword MYAPP_UPLOAD_STORE_PASSWORD
            keyAlias MYAPP_UPLOAD_KEY_ALIAS
            keyPassword MYAPP_UPLOAD_KEY_PASSWORD
        }
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        // Caution! In production, you need to generate your own keystore file.
        // see https://reactnative.dev/docs/signed-apk-android.
        signingConfig signingConfigs.release
        minifyEnabled enableProguardInReleaseBuilds
        shrinkResources enableShrinkResource  
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro"
    ndk {
    debugSymbolLevel 'FULL'
}
    }
}

  packagingOptions {
    pickFirst "lib/armeabi-v7a/libc++_shared.so"
    pickFirst "lib/arm64-v8a/libc++_shared.so"
    pickFirst "lib/x86/libc++_shared.so"
    pickFirst "lib/x86_64/libc++_shared.so"
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // https://developer.android.com/studio/build/configure-apk-splits.html
        // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
        def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    defaultConfig.versionCode * 1000 + versionCodes.get(abi)
        }

    }
}

}

dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'com.android.support:multidex:2.0.1' implementation project(':react-native-code-push')

//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"  // From node_modules
implementation("com.facebook.soloader:soloader:0.10.4")     // for soloader issue crash for this RN version
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
    implementation jscFlavor
}

}

if (isNewArchitectureEnabled()) { // If new architecture is enabled, we let you build RN from source // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. // This will be applied to all the imported transtitive dependency. configurations.all { resolutionStrategy.dependencySubstitution { substitute(module("com.facebook.react:react-native")) .using(project(":ReactAndroid")).because("On New Architecture we're building React Native from source") } } }

// Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.implementation into 'libs' }

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

def isNewArchitectureEnabled() { // To opt-in for the New Architecture, you can either: // - Set newArchEnabled to true inside the gradle.properties file // - Invoke gradle with -newArchEnabled=true // - Set an environment variable ORG_GRADLE_PROJECT_newArchEnabled=true return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" } apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" apply plugin: 'com.google.gms.google-services'

import org.apache.tools.ant.taskdefs.condition.Os

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript { ext { buildToolsVersion = "31.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 appCompatVersion = "1.4.2" googlePlayServicesLocationVersion = "20.0.0" if (System.properties['os.arch'] == "aarch64") { // For M1 Users we need to use the NDK 24 which added support for aarch64 ndkVersion = "24.0.8215888" } else { // Otherwise we default to the side-by-side NDK version from AGP. ndkVersion = "21.4.7075529" } } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle:7.0.4") classpath("com.bugsnag:bugsnag-android-gradle-plugin:7.+") classpath("com.facebook.react:react-native-gradle-plugin") classpath("de.undercouch:gradle-download-task:4.1.2") classpath 'com.google.gms:google-services:4.3.15' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }

allprojects { repositories { exclusiveContent { // We get React Native's Android binaries exclusively through npm, // from a local Maven repo inside node_modules/react-native/. // (The use of exclusiveContent prevents looking elsewhere like Maven Central // and potentially getting a wrong version.) filter { includeGroup "com.facebook.react" } forRepository { maven { url "$rootDir/../node_modules/react-native/android" } } } maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } mavenCentral { // We don't want to fetch react-native from Maven Central as there are // older versions over there. content { excludeGroup "com.facebook.react" } } google()

     // Added for react-native-image-crop-picker
    maven { url 'https://maven.google.com' }

    maven { url 'https://www.jitpack.io' }

    maven {
       // Required for react-native-background-geolocation
       url("${project(':react-native-background-geolocation').projectDir}/libs")
    }
    maven {
       // Required for react-native-background-fetch
       url("${project(':react-native-background-fetch').projectDir}/libs")
    }
}

}

## Expected Behavior
<!--- Tell us what should happen -->

## Actual Behavior
<!--- Tell us what happens instead -->

## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1.
2.
3.
4.

## Context
<!--- What were you trying to do? -->

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details><summary>Logs</summary>

``` <!-- Syntax highlighting:  DO NOT REMOVE -->
PASTE_YOUR_LOGS_HERE

java.lang.NoClassDefFoundError: com.transistorsoft.locationmanager.adapter.TSConfig at com.transistorsoft.locationmanager.service.ForegroundNotification.createNotificationChannel(Unknown:49) at com.transistorsoft.locationmanager.notification.TSLocalNotification.build(Unknown:1) at com.transistorsoft.locationmanager.service.ForegroundNotification.build(Unknown) at com.transistorsoft.locationmanager.service.AbstractService.doStartForeground(Unknown:18) at com.transistorsoft.locationmanager.service.AbstractService.doCreate(Unknown:5) at com.transistorsoft.locationmanager.service.TrackingService.onCreate(Unknown:6) at android.app.ActivityThread.handleCreateService(ActivityThread.java:4485) at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2161) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7872) at java.lang.reflect.Method.invoke(Method.java:-2) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Caused by: java.lang.ExceptionInInitializerError at com.transistorsoft.locationmanager.adapter.TSConfig.getInstance(Unknown) at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.(RNBackgroundGeolocationModule.java:95) at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocation.createNativeModules(RNBackgroundGeolocation.java:19) at com.facebook.react.ReactPackageHelper.getNativeModuleIterator(ReactPackageHelper.java:42) at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:42) at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1476) at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1447) at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1341) at com.facebook.react.ReactInstanceManager.access$1200(ReactInstanceManager.java:138) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1111) at java.lang.Thread.run(Thread.java:1012)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference at com.transistorsoft.tslocationmanager.Application.q(Unknown:27) at com.transistorsoft.locationmanager.adapter.TSConfig.(Unknown:2) at com.transistorsoft.locationmanager.adapter.TSConfig.getInstance(Unknown) at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.(RNBackgroundGeolocationModule.java:95) at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocation.createNativeModules(RNBackgroundGeolocation.java:19) at com.facebook.react.ReactPackageHelper.getNativeModuleIterator(ReactPackageHelper.java:42) at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:42) at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1476) at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1447) at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1341) at com.facebook.react.ReactInstanceManager.access$1200(ReactInstanceManager.java:138) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1111) at java.lang.Thread.run(Thread.java:1012)

vksgautam1986 commented 6 months ago

bugsnag_error_stacktrace_java.lang.NoClassDefFoundError_event_6633798a00e6ec1a88360000.txt

christocracy commented 6 months ago

def enableShrinkResource = true

Make it false

vksgautam1986 commented 6 months ago

thanks although it did not work and i tried every other solution and even removed proguarding and shrinking as well but giving issue with other libraries