简体   繁体   English

android中的失败[INSTALL_FAILED_USER_RESTRICTED: Invalid apk]

[英]Failure [INSTALL_FAILED_USER_RESTRICTED: Invalid apk] in android

I am using Android Studio 3.0.1.我正在使用 Android Studio 3.0.1。
When i am trying to run app当我尝试运行应用程序时

INSTALL_FAILED_USER_RESTRICTED: Invalid apk INSTALL_FAILED_USER_RESTRICTED:无效的apk

error occurs.发生错误。

I also disable Instant Run.我还禁用了即时运行。

在此处输入图像描述

again i am run app but same error occurs.我再次运行应用程序,但发生同样的错误。

04/04 10:59:08: Launching app 04/04 10:59:08:启动应用程序
$ adb push G:\Android\Fundraiser\BuyForFund\app\build\outputs\apk\debug\app-debug.apk /data/local/tmp/com.android.buyforfund $ adb push G:\Android\Fundraiser\BuyForFund\app\build\outputs\apk\debug\app-debug.apk /data/local/tmp/com.android.buyforfund
$ adb shell pm install -t -r "/data/local/tmp/com.android.buyforfund" $ adb shell pm install -t -r "/data/local/tmp/com.android.buyforfund"
Failure [INSTALL_FAILED_USER_RESTRICTED: Invalid apk]失败 [INSTALL_FAILED_USER_RESTRICTED:无效的 apk]

$ adb shell pm uninstall com.android.buyforfund $ adb shell 下午卸载 com.android.buyforfund
DELETE_FAILED_INTERNAL_ERROR DELETE_FAILED_INTERNAL_ERROR
Error while Installing APK安装 APK 时出错

I have the same problem, I sent a feedback to Google on my phone, would say it's a bug. 我有同样的问题,我在手机上向谷歌发送反馈,会说这是一个错误。 In my case the best solution is to cancel that dialog and then re-run, it works always on second attempt after cancelling. 在我的情况下,最好的解决方案是取消该对话,然后重新运行,它取消后始终在第二次尝试。

Depending on what phone you are using, I would assume the problem is on the phone (Google) side. 根据您使用的手机,我会假设问题出在手机(谷歌)方面。 Not sure yet if a general Google problem or specific hardware phones, I use "Xiaomi Redmi 5". 目前还不确定是否存在Google常见问题或特定硬件手机,我使用的是“小米Redmi 5”。

Disabling instant run actually worked in my case, but that's not the purpose of it, that's just a dirty workaround. 禁用即时运行实际上在我的情况下工作,但这不是它的目的,这只是一个肮脏的解决方法。

Edit: Make sure that you don't have something like 编辑:确保您没有类似的东西

android:debuggable="false"

in your manifest. 在你的清单中。

None of the other answers worked for me using Xiaomis MIUI 10 on a Mi 9 phone. 在Mi 9手机上使用Xiaomis MIUI 10 ,其他任何答案都没有。

Besides the usual (like enabling USB debugging and Install via USB in the developer options) answers from other questions suggested turning off MIUI optimization . 除了通常的(如启用USB debugging和在开发人员选项中Install via USB ),其他问题的答案建议关闭MIUI optimization While this did the trick, I wasn't happy with it. 虽然这样做了,但我对此并不满意。 So I did some digging and came to the following conclusions: 所以我做了一些挖掘并得出以下结论:

The described error only occurred the second time you deploy your app and after that keeps occurring every other time when deploying the same app to that phone. 所描述的错误仅在您第二次部署应用程序时发生,之后在将相同应用程序部署到该电话时每隔一段时间发生一次。

To solve this I could either hit Run / press Shift + F10 again or unplug and plug in that phone again. 为了解决这个问题,我可以再次点击Run / Press Shift + F10 ,或者重新插上电源并重新插入手机。 None of this seems viable. 这似乎都不可行。 So I did some more digging and it turns out when you are increasing the versionCode in your build.gradle file every time you build your app, MIUI 10 will not complain and let you install your app just like you would expect. 所以我做了一些挖掘,当你每次构建应用程序时在build.gradle文件中增加versionCode时, MIUI 10都不会抱怨,让你按照预期安装应用程序。 Even Android Studios Instant Run works. 甚至Android Studios Instant Run可以。 Though doing this manually is just as annoying. 虽然手动执行此操作同样令人讨厌。

So I took some ideas to auto-increment the versionCode from this question and modified build.gradle (the one for your module, NOT the one for your project). 所以我采取了一些想法从这个问题中自动增加versionCode并修改了build.gradle (模块的那个,而不是你项目的那个)。 You can do the same following these easy steps: 您可以按照以下简单步骤执行相同操作:

Replace 更换

defaultConfig {
    applicationId "your.app.id" // leave it at the value you have in your file
    minSdkVersion 23 // this as well
    targetSdkVersion 28 // and this
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

with

def versionPropsFile = file('version.properties')
def value = 0

Properties versionProps = new Properties()

if (!versionPropsFile.exists()) {
    versionProps['VERSION_MAJOR'] = "1"
    versionProps['VERSION_MINOR'] = "0"
    versionProps['VERSION_PATCH'] = "0"
    versionProps['VERSION_BUILD'] = "0"
    versionProps.store(versionPropsFile.newWriter(), null)
}

def runTasks = gradle.startParameter.taskNames
if ('assembleRelease' in runTasks) {
    value = 1
}

if (versionPropsFile.canRead()) {

    versionProps.load(new FileInputStream(versionPropsFile))

    versionProps['VERSION_PATCH'] = (versionProps['VERSION_PATCH'].toInteger() + value).toString()
    versionProps['VERSION_BUILD'] = (versionProps['VERSION_BUILD'].toInteger() + 1).toString()

    versionProps.store(versionPropsFile.newWriter(), null)

    // change major and minor version here
    def mVersionName = "${versionProps['VERSION_MAJOR']}.${versionProps['VERSION_MINOR']}.${versionProps['VERSION_PATCH']}"

    defaultConfig {
        applicationId "your.app.id" // leave it at the value you have in your file
        minSdkVersion 23 // this as well
        targetSdkVersion 28 // and this
        versionCode versionProps['VERSION_BUILD'].toInteger()
        versionName "${mVersionName} Build: ${versionProps['VERSION_BUILD']}"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
}
else {
    throw new GradleException("Could not read version.properties!")
}

Now each time you build your app by hitting Run or Instant Run your versionCode / VERSION_BUILD increases. 现在,每次通过点击Run或“ Instant Run构建应用程序时,您的versionCode / VERSION_BUILD增加。 If you build a release your VERSION_PATCH increases as well changing your versionName from xyz to xyz+1 (ie 1.2.3 turns to 1.2.4 ). 如果你构建一个版本,你的VERSION_PATCH也会增加,你的versionName也会从xyz更改为xyz+1 (即1.2.3转为1.2.4 )。 To change VERSION_MAJOR (the x ) and VERSION_MINOR (the y ) edit the version.properties file which you can find in your module folder. 要更改VERSION_MAJORx )和VERSION_MINORy ),请编辑可在模块文件夹中找到的version.properties文件。 If you didn't change your modules name it's called app so this file is located at app/version.properties . 如果您没有更改模块名称,则称为app因此该文件位于app/version.properties

Make sure you have enabled the following options: 确保您已启用以下选项:

Settings > Additional Settings > Developer options 设置>其他设置>开发人员选项

  1. USB Debugging USB调试
  2. Install via USB 通过USB安装
  3. USB Debugging (Security settings) USB调试(安全设置)

For those who still might get this error if you have done everything from enabling to flutter clean and all.如果您已经完成了从启用到flutter clean等所有操作,对于那些仍然可能会收到此错误的人。 I solved this error by checking the manifest and adding proper value because i changed something in the manifest which was not supported and later forgot to change it.我通过检查清单并添加正确的值来解决此错误,因为我更改了清单中不支持的内容,后来忘记更改它。 so if you have changed something in theme, drawable or any resource file check that out first.因此,如果您更改了主题、可绘制对象或任何资源文件中的某些内容,请先检查一下。

If you are targeting android 'P' then your build.gradle file should look like this 如果你的目标是android'P',那么你的build.gradle文件应该是这样的

android {
    compileSdkVersion 'android-P'
    defaultConfig {
        applicationId "xyz.com"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

targetSdkVersion must be 27 to run your app below android 'P', otherwise the app can only run on 'P' and above. targetSdkVersion必须为27才能在android'P'下运行您的应用程序,否则该应用程序只能在'P'及以上运行。

INSTALL_FAILED_USER_RESTRICTED: Invalid apk Steps for MIUI 9 and Above: INSTALL_FAILED_USER_RESTRICTED:MIUI 9 及更高版本的 apk 步骤无效

Settings -> Additional Settings -> Developer options -> step 1: scroll down side - Turn off "MIUI optimization" and Restart your device.设置 -> 附加设置 -> 开发者选项 ->步骤 1:向下滚动 - 关闭“MIUI 优化”并重新启动您的设备。 step 2: Turn On "USB Debugging" step 3: Turn On "Install via USB" step 4: show push notification and just click USB - Set USB Configuration to Charging (MTP(Media Transfer Protocol) is the default mode. Works even in MTP in some cases).第 2 步:打开“USB 调试”第 3 步:打开“通过 USB 安装”第 4 步:显示推送通知,然后单击 USB - 将 USB 配置设置为充电(MTP(媒体传输协议)是默认模式。即使在MTP 在某些情况下)。 please try.请试试。

I ran into this same error while the underlying issue was different.当根本问题不同时,我遇到了同样的错误。

Mine was that I was trying to install my app on Android 12 device while the AndroidManifest.xml file didn't have all the android:exported properties explicitly set.我的是我试图在 Android 12 设备上安装我的应用程序,而AndroidManifest.xml文件没有明确设置所有android:exported属性。 This error is explained further here: https://developer.android.com/about/versions/12/behavior-changes-12#exported此处进一步解释了此错误: https ://developer.android.com/about/versions/12/behavior-changes-12#exported

If your app targets Android 12 or higher and contains activities, services, or broadcast receivers that use intent filters, you must explicitly declare the android:exported attribute for these app components .如果您的应用面向 Android 12 或更高版本并包含使用 Intent 过滤器的活动、服务或广播接收器,则您必须为这些应用组件显式声明android:exported属性

Warning: If an activity, service, or broadcast receiver uses intent filters and doesn't have an explicitly-declared value for android:exported , your app can't be installed on a device that runs Android 12 or higher .警告:如果活动、服务或广播接收器使用意图过滤器并且没有明确声明的android:exported值,则您的应用无法安装在运行 Android 12 或更高版本的设备上

After I added the required android:exported properties into AndroidManifest.xml file, the error was resolved.在我将所需的android:exported属性添加到AndroidManifest.xml文件后,错误得到解决。

In your Androidmanifest.xml file at path在路径的Androidmanifest.xml文件中

app/src/main/Androidmanifest.xml应用程序/src/main/Androidmanifest.xml

add android:exported="true"` in activity tag.在活动标签中添加 android:exported="true"`。

Sample:样本:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.example">
   <application
        android:label="example"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize"
            android:exported="true">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 工作室:失败 [INSTALL_FAILED_USER_RESTRICTED] - Android Studio: Failure [INSTALL_FAILED_USER_RESTRICTED] “无法完成会话:INSTALL_FAILED_USER_RESTRICTED:无效的APK。” - “Failed to finalize session : INSTALL_FAILED_USER_RESTRICTED: Invalid apk.” INSTALL_FAILED_USER_RESTRICTED:android studio 使用 redmi 4 设备 - INSTALL_FAILED_USER_RESTRICTED : android studio using redmi 4 device INSTALL_FAILED_USER_RESTRICTED 通过 USB 安装被禁用 - INSTALL_FAILED_USER_RESTRICTED Installation via USB is disabled 无法安装应用程序:INSTALL_FAILED_USER_RESTRICTED - The application could not be installed: INSTALL_FAILED_USER_RESTRICTED INSTALL_FAILED_USER_RESTRICTED:安装被用户通过 adb 安装应用程序取消(无 SIM 卡) - INSTALL_FAILED_USER_RESTRICTED: Install canceled by user install apps via adb (no Sim Card) 部署失败:INSTALL_FAILED_USER_RESTRICTED:安装被用户取消,没有弹出允许窗口 - Deployment failed: INSTALL_FAILED_USER_RESTRICTED: Install canceled by User without allow-window popping up 失败 [INSTALL_FAILED_INVALID_APK] - Failure [INSTALL_FAILED_INVALID_APK] 构建和部署android studio项目失败[INSTALL_FAILED_INVALID_APK] - Failure [INSTALL_FAILED_INVALID_APK] on building and deploying android studio project 无法安装APK [INSTALL_FAILED_DEXOPT] Android Studio - Failure to install APK [INSTALL_FAILED_DEXOPT] Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM