react-native-background-geolocation: FATAL Exception: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp/com.intentfilter.androidpermissions.PermissionsActivity}

The plugin works perfectly on iOS, but has some issues on Android.

Stacktrace is as follows:

android.content.ActivityNotFoundException: Unable to find explicit 
activity class {com.myapp/com.intentfilter.androidpermissions.PermissionsActivity}; 
have you declared this activity in your AndroidManifest.xml?
   at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1801)
   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514)
   at android.app.ContextImpl.startActivity(ContextImpl.java:687)
   at android.app.ContextImpl.startActivity(ContextImpl.java:669)
   at android.content.ContextWrapper.startActivity(ContextWrapper.java:337)
   at com.intentfilter.androidpermissions.PermissionManager.startPermissionActivity(PermissionManager.java:63)
   at com.intentfilter.androidpermissions.PermissionHandler.requestPermissions(PermissionHandler.java:70)
   at com.intentfilter.androidpermissions.PermissionHandler.checkPermissions(PermissionHandler.java:47)
   at com.intentfilter.androidpermissions.PermissionManager.checkPermissions(PermissionManager.java:50)
   at com.transistorsoft.locationmanager.util.b$2.run(Unknown Source)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:148)
   at android.app.ActivityThread.main(ActivityThread.java:5461)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

android/build.gradle

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com'
            name 'Google'
        }
        maven { url "https://jitpack.io" }
        maven { url "$rootDir/../node_modules/react-native-background-geolocation/android/libs" }
        maven { url "$rootDir/../node_modules/react-native-background-fetch/android/libs" }
    }
}

ext {
    compileSdkVersion   = 27
    targetSdkVersion    = 27
    buildToolsVersion   = "27.0.3"
    supportLibVersion   = "27.1.1"
    googlePlayServicesVersion = "15.0.0"
}

android/app/build.gradle

apply plugin: "com.android.application"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

import com.android.build.OutputFile

apply from: "../../node_modules/react-native/react.gradle"

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 16
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 2
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation(project(':react-native-maps')){
       exclude group: 'com.google.android.gms', module: 'play-services-base:+'
       exclude group: 'com.google.android.gms', module: 'play-services-maps:+'
    }
    implementation 'com.google.android.gms:play-services-base:+'
    implementation 'com.google.android.gms:play-services-maps:+'
    
    implementation (project(':react-native-background-geolocation')) {
        exclude group: 'com.google.android.gms', module: 'play-services-location:+'
    }
    implementation ("com.google.android.gms:play-services-location:+") {
        force = true;
    }
    implementation project(':react-native-background-fetch')
    implementation (project(':react-native-device-info')) {
        exclude group: 'com.google.android.gms', module: 'play-services-gcm:+'
    }
    implementation ("com.google.android.gms:play-services-gcm:+") {
        force = true;
    }
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-camera')
    implementation project(':bugsnag-react-native')
    implementation project(':reactnativesignaturecapture')
}

task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

AndroidManifest.xml has following data

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

Your Environment

  • Plugin version: 2.12.2
  • Platform: Android
  • OS version: Android 6.0.1 (Cyanogen OS version 13.1.2)
  • Device manufacturer / model: OnePlus One (1+ 1)
  • React Native version (react-native -v): 0.54.0
  • React version: 16.3.2
  • Plugin config

Expected Behavior

Should display alert box asking to activate location service

Actual Behavior

The app closes abruptly and displays a message as “Unfortunately, myapp has stopped.”

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 34 (16 by maintainers)

Most upvoted comments

@christocracy : I was able to circumvent the issue by adding following line of code in AndroidManifest.xml file

Added following peace of code inside ‘application’ tag

<activity android:name="com.intentfilter.androidpermissions.PermissionsActivity" />

Now application asks user to ‘Deny’ or ‘Allow’ access to device’s location. [The application does not closes abruptly].

But there is a new issue, if user comes back to the same scene second time, a warning is displayed as follows.

Possible Unhandled Promise Rejection (id: 1):
"Waiting for previous start action to complete"