安装 APK 无效,但从 Android studio 部署有效

Installing APK not working, but deploying from Android studio works

编辑

APK 是一个有问题的签名 APK,而直接从 android studio 安装不会导致任何问题。 (仅使用 APK)。

应用开发完成后,我尝试生成一个 APK 给朋友测试;他说它不起作用(不可安装)。所以我用 Android 6.0.1 抓住了 phone 摩托罗拉,并试图从 Android 工作室中的 Android 监视器调试问题,这是那里的错误:

unable to parse package file android

然后我在我用来测试的 phone 上尝试了相同的 APK(三星 J3 5.1.1 Android 版本)并在 [=45 的日志中出现以下错误=]班长:

Class not found when unmarshalling: com.android.packageinstaller.InstallFlowAnalytics

我以前从未有过这个或类似的东西,用谷歌搜索了一下并试图在 SOF 上找到答案找到了几个 none 有效的答案。

正如我所说 none 这些有效,知道吗?

这是我的清单和我的 Gradle 文件:

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="my.package.myapp">

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

    <application
        android:icon="@drawable/ice_launder"
        android:label="@string/app_name"
        android:roundIcon="@drawable/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="my.package.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="my.package.MoreLikeThisActivity" />
        <activity android:name="my.package.SearchResultActivity" />
        <activity android:name="my.package.LastResultsActivity" />
        <activity android:name="my.package.CompanyDetailsActivity" />
        <activity android:name="my.package.OnboardingActivity"/>
    </application>

</manifest>

Gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "my.package.myapp"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral() // jcenter() works as well because it pulls from Maven Central
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.github.bumptech.glide:glide:4.0.0'
    compile 'com.github.navasmdc:MaterialDesign:1.5@aar'
    compile 'com.ogaclejapan.smarttablayout:library:1.2.1@aar'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
}

只需通过“构建”>“构建 APK”来构建您的项目

在使用已签名的 apk 时,请确保您已选中复选框 v1 和 v2

如果您要生成签名的 apk,则需要检查两个签名版本: V1(Jar 签名)和 V2(完整的 Apk 签名),这样您的 apk 将在所有具有 api 级别的设备中 运行,如您在 build.gradle 文件中定义的那样。

你可以参考这个: https://source.android.com/security/apksigning/v2.html#verification

In Android 7.0, APKs can be verified according to the APK Signature Scheme v2 (v2 scheme) or JAR signing (v1 scheme). Older platforms ignore v2 signatures and only verify v1 signatures.

清理项目、使缓存无效并重新启动对我有用。