Cordova 发布构建的 APK 无法安装在 Android 上

Pie*_*ric 5 android apk cordova

命令“Cordova build android”生成一个名为 app-debug.apk 的 apk 文件,我可以将其安装在我的设备上(Samsung A3 with Android v8.0)

命令“Cordova build android --release”会生成一个名为 app-release-unsigned.apk 的 apk 文件,该文件不会安装在同一设备上(“未安装应用程序”)。

我还必须补充一点,我不是要在 Playstore 上发布该 apk。我也尝试签署 APK,但它不会改变结果。

这两个文件之间的本质区别应该是什么?导致发布版本失败的原因可能是什么?

这是位于 Cordova 项目文件夹中的 config.xml 的内容:

<?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>
Run Code Online (Sandbox Code Playgroud)

以下是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>
Run Code Online (Sandbox Code Playgroud)

编辑:这是我用于 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": ""
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Nid*_*eph 2

调试构建和发布构建是两个不同的东西。第一个适用于开发人员,而第二个适用于您的用户。为了在 Cordova 中生成发布版本,您可以使用Cordova CLI或使用Android Studio.

科尔多瓦 CLI

为了使用 CLI 进行发布构建,您需要cordova build --release使用一组参数来运行。在没有配置的情况下运行命令不会成功构建。这些参数是为 Play 商店签署您的应用程序所必需的。此外,这些配置可以在 cli 中提供,也可以通过build.json配置文件提供。有关签署应用程序的 Cordova 文档可以让您更深入地了解这一点。

安卓工作室

这种方式是一种相对简单的发布版本构建方式。您在这里所需要做的就是将您的应用程序加载到 android studio,然后按照屏幕说明如何 生成签名的 apk来获取发布版本。它会要求您创建一个密钥文件,这是未来版本所必需的。