安装 APK 不起作用,但从 Android studio 部署可以工作

问题描述 投票:0回答:4

编辑

APK 是经过签名的,存在问题,而直接从 android studio 安装则不会出现任何问题。 (仅使用APK)。

开发完应用程序后,我尝试生成一个APK并发送给朋友测试;他说它不起作用(无法安装)。所以我抓住了带有 Android 6.0.1 的摩托罗拉手机,并尝试从 Android studio 中的 Android 监视器调试问题,这就是那里的错误:

无法解析android包文件

然后我在我用来测试的同一部手机上尝试了相同的APK(三星J3,Android版本为5.1.1),并在Android监视器的日志中收到以下错误:

解组时未找到类: com.android.packageinstaller.InstallFlowAnalytics

我以前从来没有遇到过这个或类似的东西,用谷歌搜索了一下并试图在 SOF 上找到答案,发现了几个答案,但没有一个起作用。

  • 禁用 proGuard
  • 将 android:extractNativeLibs="true" 添加到清单中
  • 增加/减少了SDK版本

正如我所说,这些都不起作用,有什么想法吗?

这是我的清单和我的 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>

摇篮

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'
}
android android-studio package-managers
4个回答
2
投票

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

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


1
投票

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

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

在Android 7.0中,可以根据APK签名来验证APK 方案 v2(v2 方案)或 JAR 签名(v1 方案)。较旧的平台 忽略 v2 签名,仅验证 v1 签名。


0
投票

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


0
投票

转到Make Project,构建完成后您可以在...AndroidStudioProjects\AppName pp uild\outputs pk\debug pp-debug.apk中找到该文件

这个文件应该安装(对我有用)

Make Project 图标位于此处: this is where the icon is on Android Studio

© www.soinside.com 2019 - 2024. All rights reserved.