-2

My Android app is working fine on the emulator, and even on the device when I connect it using a USB cable. However, when I generate the apk file and share it with others, the app won't work. It crashes after the splash screen is launched.

Here is my app/build.gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId 'com.test'
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 2
        versionName "1.1"

        multiDexEnabled true

        def serverPropertiesFile = rootProject.file("server.properties")

        // Initialize a new Properties() object called keystoreProperties.
        def serverProperties = new Properties()

        // Load your keystore.properties file into the serverProperties object.
        serverProperties.load(new FileInputStream(serverPropertiesFile))


        buildConfigField("String", "HOST", serverProperties['SERVER_URL'])
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    productFlavors {
    }
    lintOptions {
        abortOnError false
} } dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.swipelayout:library:1.2.0@aar'
    compile 'com.daimajia.androidanimations:library:1.1.2@aar'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.google.android.gms:play-services-gcm:10.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.google.code.gson:gson:2.8.2'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

Manifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Any help?

Pang
  • 9,564
  • 146
  • 81
  • 122
Jacky
  • 298
  • 3
  • 15

4 Answers4

2

I think you are lacking Runtime Permissions on API 23 or Above

Try giving Runtime permissions for Camera, Location and Phone. Here are examples of adding runtime permission.

https://developer.android.com/training/permissions/requesting.html

How to check Grants Permissions at Run-Time?

https://www.androidhive.info/2016/11/android-working-marshmallow-m-runtime-permissions/

To check if lacking runtime permission is the problem Go to Phone Settings -> Apps -> Installed App -> Your App -> Permissions -> Allow Permissions there

Tomin B Azhakathu
  • 2,656
  • 1
  • 19
  • 28
2

I think you need to add some classes to your pro-guard file. Gson for example won't handle obfuscated very well. To see if this actually causes the problem, remove minifyEnabled true.

Robin Dijkhof
  • 18,665
  • 11
  • 65
  • 116
0

Go to build and then click on generate/build apk. The apks generated by clicking on run are for devices with same API level.

kunwar97
  • 775
  • 6
  • 14
0

I think you have the problem in APK version. check your mobile APK version and your targeted APK version. your App will not run Lower then APK version 25 as you built with 25.0.0

Md . Sojib Ahmed
  • 431
  • 4
  • 14