简体   繁体   中英

Cordova release built APK cannot be installed on Android

Command "Cordova build android" produces an apk file named app-debug.apk that I can install on my device (Samsung A3 with Android v8.0)

Command "Cordova build android --release" produces an apk file named app-release-unsigned.apk that won't install on same device ("App not installed").

I must also add that I am not trying to publish that apk on a Playstore. I also tried to sign the APK but it doesn't change the outcome.

What should be the essential differences between these 2 files? What could be the reasons causing the release version to fail?

Here is the content of config.xml located in the Cordova project folder:

<?xml version='1.0' encoding='utf-8'?>
<widget id="eu.jrc.treechecker" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>TreeChecker</name>
    <description>
        A mobile application 
    </description>
    <author email="*******" href="********">
        Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" /> 
    <access origin="*" />
    <icon src="www/img/ic_canhemon.png" />
    <platform name="android">
        <allow-intent href="market:*" />
        <preference name="android-minSdkVersion" value="24" />
        <preference name="android-targetSdkVersion" value="28" />
    </platform>
    <plugin name="cordova-plugin-camera" spec="^4.0.3" />
    <plugin name="cordova-plugin-spinner-dialog" spec="^1.3.1" />
    <plugin name="cordova-plugin-dbcopy" spec="^2.1.2" />
    <plugin name="cordova-sqlite-storage" spec="^3.1.0" />
</widget>

Here is the content of platforms/android/app/src/main/AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="eu.jrc.treechecker" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
        </provider>
    </application>
    <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="28" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

EDIT : Here is what I would use for a build.json:

{
    "android": {
        "debug": {
            "keystore": "appname-mobileapps.keystore",
            "storePassword": "***",
            "alias": "appname-mobileapps",
            "password" : "***",
            "keystoreType": ""
        },
        "release": {
            "keystore": "appname-mobileapps.keystore",
            "storePassword": "***",
            "alias": "appname-mobileapps",
            "password" : "***",
            "keystoreType": ""
        }
    }
}

The debug build and release build are two different things. The first one is meant for developers whereas the second one is for your users. In order to produce a release build in Cordova, you can either use the Cordova CLI or use Android Studio .

Cordova CLI

In order to make a release build using the CLI, you will need to run cordova build --release along with a set of arguments. Running the command without configs would not give a successful build. These arguments are necessary to sign your app for play store. Further, these configs can be supplied either in the cli or by having a build.json config file. Cordova docs on Signing an App gives you more insight into this.

Android Studio

This way is a relatively easy way to make a release build. All you need to do here is to load your app onto the android studio, and then follow the screen instructions on how to Generate Signed apk to obtain a release version. It will ask you to create a key file, which is required for future releases.

I accepted the answer above but I post here what I did step by step, also because the method proposed on cordova website did not work for me.

# build apk
cordova build android --release

# sign apk (I used keytool to create mykeystore)
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <mykeystore> <PATH-TO-app-release-unsigned.apk> <appname-alias>

# align apk
zipalign -v 4 <PATH-TO-app-release-unsigned.apk> <final-apk-name>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM