我使用的是Android Studio 3.0.1。
当我尝试运行应用程序时
INSTALL_FAILED_USER_RESTRICTED:无效的apk
出现错误。
我还禁用了即时运行。

再一次,我正在运行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.buyforFoundation
$ adb shell pm安装本地数据“/ -t / -r /tmp/com.android.buyforfund”
失败INSTALL_FAILED_USER_RESTRICTED:无效的apk
$ adb shell pm卸载com.android.buyforfund
DELETE_FAILED_INTERNAL_ERROR
安装APK时出错
发布于 2018-04-28 23:34:03
我也有同样的问题,我在手机上给Google发了一个反馈,说这是个bug。在我的例子中,最好的解决方案是取消该对话框,然后重新运行,它总是在取消后的第二次尝试中起作用。
根据你使用的手机,我认为问题出在手机(谷歌)这一端。还不确定是一般的Google问题还是特定的硬件手机,我使用“小米Redmi 5”。
在我的例子中,禁用即时运行实际上是有效的,但这不是它的目的,那只是一个肮脏的变通方法。
编辑:确保你没有像这样的东西
android:debuggable="false"在你的载货单上。
发布于 2018-04-04 13:57:05
确保您已启用以下选项:
设置>附加设置>开发人员选项
发布于 2019-06-20 14:56:00
对于我在小米9手机上使用小米MIUI 10,其他答案都不起作用。
除了通常的(如在开发人员选项中启用USB debugging和Install via USB ),来自其他问题的答案建议关闭MIUI optimization。虽然这样做起到了作用,但我对此并不满意。因此,我做了一些挖掘,得出了以下结论:
所描述的错误只在你第二次部署你的应用程序时发生,之后在将相同的应用程序部署到手机上时,每隔一次就会发生一次。
要解决这个问题,我可以再次点击Run /按下Shift + F10,或者再次拔出并插入该电话。所有这些似乎都不可行。所以我做了更多的挖掘,当你每次构建你的应用程序时,当你在build.gradle文件中增加versionCode时,MIUI 10不会抱怨,让你按照你期望的那样安装你的应用程序。即使是Android Studios Instant Run也能工作。尽管手动做这件事同样令人讨厌。
因此,我采用了一些想法来自动递增this question中的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从x.y.z改为x.y.z+1 (即1.2.3变成1.2.4)。要更改VERSION_MAJOR ( x)和VERSION_MINOR ( y),请编辑您可以在模块文件夹中找到的version.properties文件。如果您没有更改模块名称,则将其命名为app,因此该文件位于app/version.properties。
https://stackoverflow.com/questions/49643613
复制相似问题