8

I am working on an android app and everything works fine when I build it in my local system and run on emulator, but as soon as I make and release and install apk on my phone, it crashes with error -

There was an error parsing the package

As you can see, I am building with latest SDK and build tools, and my phone is running the same version on API too. I have Untrusted Sources installation allowed too.

I am taking help of "Build a release version" section on this link. It is generating a file like - app-release-unsigned.apk in my app/build/outputs/apk folder. Please help with it.

Emulator AVD -

Galaxy Nexus, 1 GB RAM, API 22 (Android 5.1.1), CPU x86

My Phone -

Nexus 5, 2 GB RAM, Android 5.1.1

build.gradle -

apply plugin: 'android'
apply plugin: 'com.android.application'

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

android {
    compileSdkVersion 22 // api version
    buildToolsVersion "22.0.1" // build tools version

    defaultConfig {
        applicationId "org.compani.proj"
        minSdkVersion 8
        targetSdkVersion 22 // same as compilesdkversion
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),  'proguard-rules.pro'
        }
    }
}

dependencies {
    dependencies {
        //compile project(':android-beacon-library')
        compile 'org.altbeacon:android-beacon-library:2+@aar'
    }
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:recyclerview-v7:21.+'
    compile 'com.android.support:cardview-v7:21.+'
    compile 'com.android.support:support-v4:+'
}

AndroidManifest.xml -

<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="22" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    android:name="MyApp">
    <activity
        android:name="org.compani.proj.MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleInstance">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

Release messages -

23:43:42: Executing external task 'assembleRelease'...
Configuration on demand is an incubating feature.
:app:preBuild
:app:preReleaseBuild
:app:checkReleaseManifest
:app:preDebugBuild
:app:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72103Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:app:prepareOrgAltbeaconAndroidBeaconLibrary214Library UP-TO-DATE
:app:prepareReleaseDependencies
:app:compileReleaseAidl UP-TO-DATE
:app:compileReleaseRenderscript UP-TO-DATE
:app:generateReleaseBuildConfig UP-TO-DATE
:app:generateReleaseAssets UP-TO-DATE
:app:mergeReleaseAssets UP-TO-DATE
:app:generateReleaseResValues UP-TO-DATE
:app:generateReleaseResources UP-TO-DATE
:app:mergeReleaseResources UP-TO-DATE
:app:processReleaseManifest
:app:processReleaseResources UP-TO-DATE
:app:generateReleaseSources UP-TO-DATE
:app:compileReleaseJava UP-TO-DATE
:app:lintVitalRelease
:app:compileReleaseNdk UP-TO-DATE
:app:preDexRelease UP-TO-DATE
:app:dexRelease UP-TO-DATE
:app:processReleaseJavaRes UP-TO-DATE
:app:packageRelease UP-TO-DATE
:app:assembleRelease

BUILD SUCCESSFUL

Total time: 6.309 secs
23:43:49: External task execution finished 'assembleRelease'.
Sam
  • 4,302
  • 12
  • 40
  • 74
  • Please install it with `adb install` and add the error code it produces. Also, is a debug build of the application installed on that device? Did you sign the unsigned APK before installation? – StenSoft Apr 16 '15 at 17:41
  • post logcat for error – Kanak Sony Apr 16 '15 at 17:42
  • I am installing it directly on device. There is no logcat. – Sam Apr 16 '15 at 17:59
  • There is a difference in `minsdkversion` in build.gradle(8) and AndroidManifest.xml(17). Correct it and try once. It might also be caused due to android-beacon library which has `targetsdkversion` as 21. Try it in device below API level 22. – Psypher Apr 16 '15 at 18:10
  • @Sam - the installation attempt itself generates output in logcat, which would be useful to see. You may need to collect this using the adb program from the command window/terminal rather than your IDE - though it looks like your issue has already been identified as trying to install an unsigned apk. – Chris Stratton Apr 16 '15 at 18:12
  • There is no error in that. I added it above. I am using Make Project->assembleRelease process to release. – Sam Apr 16 '15 at 18:14
  • No, you added messages from the build process, not logcat output generated during the install attempt. The latter would probably have been informative, but it's beside the point as you already have your answer. – Chris Stratton Apr 16 '15 at 18:17

1 Answers1

12

The generate APK is unsigned (app-release-unsigned.apk). You can't install an unsigned APK on physical device. You have two options:

Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
  • You are correct. I missed that part. So, do I still need to make project, then assembleRelease to generate unsigned one? Just want to understand the process a little better. – Sam Apr 16 '15 at 18:22
  • Sorry but I don't understand, why you need an unsigned apk? – Mattia Maestrini Apr 16 '15 at 18:25
  • I am asking as I am not sure how the process works on android. So, the generate signed apk should take care of build -> release -> signing right? – Sam Apr 16 '15 at 18:27
  • Sure, i suggest you to use the "Signing Your App in Android Studio" method, it's the easiest. Following the steps in the guide you obtain a signed APK ready to be distribute to your users – Mattia Maestrini Apr 16 '15 at 18:30
  • Sure, I was able to install. Thanks. – Sam Apr 16 '15 at 18:35
  • 2
    Who said you can't install an unsigned APK on physical device ?? – Sharp Edge Oct 09 '18 at 08:10
  • @SharpEdge From [source.android.com](https://source.android.com/security/apksigning): _Applications that attempt to install without being signed will be rejected by either Google Play or the package installer on the Android device._ – Mattia Maestrini Oct 09 '18 at 08:36
  • Well I send debug APKs all the time to people for testing, and so far only 1 has complained about it not being installed, rest of them have no issue installing it. I've even installed unsigned apks on my device. – Sharp Edge Oct 09 '18 at 08:37
  • Debug APKs are signed with debug keystore as stated on [developer.android.com](https://developer.android.com/studio/publish/app-signing#debug-mode) – Mattia Maestrini Oct 09 '18 at 08:41
  • @MattiaMaestrini Well how is being signed with the debug keystore any better than not being signed at all? – Michael Pfaff Jul 15 '20 at 21:27