Unn*_*dia 5 android failed-installation adb apk android-studio
我正在使用Android Studio 3.0.1。
当我尝试运行应用程序时
INSTALL_FAILED_USER_RESTRICTED:无效的APK
发生错误。
我也禁用即时运行。
我再次运行应用程序,但发生相同的错误。
04/04 10:59:08:启动app
$ 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 pm卸载com.android.buyforfund
DELETE_FAILED_INTERNAL_ERROR
安装APK 时出错
小智 10
我遇到了同样的错误,但根本问题不同。
我的情况是,我试图在 Android 12 设备上安装我的应用程序,但该AndroidManifest.xml文件没有android:exported明确设置所有属性。此错误在这里进一步解释:https ://developer.android.com/about/versions/12/behavior-changes-12#exported
如果您的应用以 Android 12 或更高版本为目标平台,并且包含使用 Intent 过滤器的活动、服务或广播接收器,则必须显式声明
android:exported这些应用组件的属性。警告:如果 Activity、服务或广播接收器使用 Intent Filter,并且没有显式声明 的值
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">
Run Code Online (Sandbox Code Playgroud)
其他答案都不适合我MIUI 10在 Mi 9 手机上使用小米。
除了通常的(例如启用USB debugging和Install via USB在开发人员选项中)其他问题的答案建议关闭MIUI optimization. 虽然这起到了作用,但我对此并不满意。所以我做了一些挖掘并得出以下结论:
所描述的错误仅在您第二次部署应用程序时发生,此后在将同一应用程序部署到该手机时每隔一段时间就会发生一次。
为了解决这个问题,我可以再次点击Run/按下Shift + F10或拔下并再次插入该手机。这些似乎都不可行。所以我做了一些更多的挖掘,结果发现,当您每次构建应用程序时增加文件versionCode中的时,不会抱怨并让您像您期望的那样安装应用程序。甚至 Android Studio 也能工作。尽管手动执行此操作同样烦人。build.gradleMIUI 10Instant 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"
}
Run Code Online (Sandbox Code Playgroud)
和
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 Code Online (Sandbox Code Playgroud)
现在,每次您通过点击或增加 / 来构建应用Run程序时。如果您构建一个版本,您的增量也会从更改为(即变为)。要更改()和(),请编辑您可以在模块文件夹中找到的文件。如果您没有更改模块名称,则会调用该文件,因此该文件位于.Instant RunversionCodeVERSION_BUILDVERSION_PATCHversionNamex.y.zx.y.z+11.2.31.2.4VERSION_MAJORxVERSION_MINORyversion.propertiesappapp/version.properties
| 归档时间: |
|
| 查看次数: |
4609 次 |
| 最近记录: |