![](/img/trans.png)
[英]Android Studio: Failure [INSTALL_FAILED_USER_RESTRICTED]
[英]Failure [INSTALL_FAILED_USER_RESTRICTED: Invalid apk] in android
我正在使用 Android Studio 3.0.1。
当我尝试运行应用程序时
INSTALL_FAILED_USER_RESTRICTED:无效的apk
发生错误。
我还禁用了即时运行。
我再次运行应用程序,但发生同样的错误。
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 shell pm install -t -r "/data/local/tmp/com.android.buyforfund"
失败 [INSTALL_FAILED_USER_RESTRICTED:无效的 apk]$ adb shell 下午卸载 com.android.buyforfund
DELETE_FAILED_INTERNAL_ERROR
安装 APK 时出错
我有同样的问题,我在手机上向谷歌发送反馈,会说这是一个错误。 在我的情况下,最好的解决方案是取消该对话,然后重新运行,它取消后始终在第二次尝试。
根据您使用的手机,我会假设问题出在手机(谷歌)方面。 目前还不确定是否存在Google常见问题或特定硬件手机,我使用的是“小米Redmi 5”。
禁用即时运行实际上在我的情况下工作,但这不是它的目的,这只是一个肮脏的解决方法。
编辑:确保您没有类似的东西
android:debuggable="false"
在你的清单中。
在Mi 9手机上使用Xiaomis MIUI 10
,其他任何答案都没有。
除了通常的(如启用USB debugging
和在开发人员选项中Install via USB
),其他问题的答案建议关闭MIUI optimization
。 虽然这样做了,但我对此并不满意。 所以我做了一些挖掘并得出以下结论:
所描述的错误仅在您第二次部署应用程序时发生,之后在将相同应用程序部署到该电话时每隔一段时间发生一次。
为了解决这个问题,我可以再次点击Run
/ Press Shift + F10
,或者重新插上电源并重新插入手机。 这似乎都不可行。 所以我做了一些挖掘,当你每次构建应用程序时在build.gradle
文件中增加versionCode
时, MIUI 10
都不会抱怨,让你按照预期安装应用程序。 甚至Android Studios Instant Run
可以。 虽然手动执行此操作同样令人讨厌。
所以我采取了一些想法从这个问题中自动增加versionCode
并修改了build.gradle
(模块的那个,而不是你项目的那个)。 您可以按照以下简单步骤执行相同操作:
更换
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"
}
同
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!")
}
现在,每次通过点击Run
或“ Instant Run
构建应用程序时,您的versionCode
/ VERSION_BUILD
增加。 如果你构建一个版本,你的VERSION_PATCH
也会增加,你的versionName
也会从xyz
更改为xyz+1
(即1.2.3
转为1.2.4
)。 要更改VERSION_MAJOR
( x
)和VERSION_MINOR
( y
),请编辑可在模块文件夹中找到的version.properties
文件。 如果您没有更改模块名称,则称为app
因此该文件位于app/version.properties
。
确保您已启用以下选项:
设置>其他设置>开发人员选项
如果您已经完成了从启用到flutter clean等所有操作,对于那些仍然可能会收到此错误的人。 我通过检查清单并添加正确的值来解决此错误,因为我更改了清单中不支持的内容,后来忘记更改它。 因此,如果您更改了主题、可绘制对象或任何资源文件中的某些内容,请先检查一下。
如果你的目标是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必须为27才能在android'P'下运行您的应用程序,否则该应用程序只能在'P'及以上运行。
INSTALL_FAILED_USER_RESTRICTED:MIUI 9 及更高版本的 apk 步骤无效:
设置 -> 附加设置 -> 开发者选项 ->步骤 1:向下滚动 - 关闭“MIUI 优化”并重新启动您的设备。 第 2 步:打开“USB 调试”第 3 步:打开“通过 USB 安装”第 4 步:显示推送通知,然后单击 USB - 将 USB 配置设置为充电(MTP(媒体传输协议)是默认模式。即使在MTP 在某些情况下)。 请试试。
当根本问题不同时,我遇到了同样的错误。
我的是我试图在 Android 12 设备上安装我的应用程序,而AndroidManifest.xml
文件没有明确设置所有android:exported
属性。 此处进一步解释了此错误: https ://developer.android.com/about/versions/12/behavior-changes-12#exported
如果您的应用面向 Android 12 或更高版本并包含使用 Intent 过滤器的活动、服务或广播接收器,则您必须为这些应用组件显式声明
android:exported
属性。警告:如果活动、服务或广播接收器使用意图过滤器并且没有明确声明的
android:exported
值,则您的应用无法安装在运行 Android 12 或更高版本的设备上。
在我将所需的android:exported
属性添加到AndroidManifest.xml
文件后,错误得到解决。
在路径的Androidmanifest.xml
文件中
应用程序/src/main/Androidmanifest.xml
在活动标签中添加 android:exported="true"`。
样本:
<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.