安装失败原因: ‘ null’-Android Studio 3.5

我已经更新 Android 工作室到3.5,因为我遇到了一个 APK 安装问题。这是唯一显示的日志:

Installation did not succeed.
The application could not be installed: INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
Installation failed due to: 'null'
Retry

在实际设备上尝试安装 APK 时会发生这种情况。如果我从设备上卸载应用程序,然后重新运行构建,它只安装一次,然后在下一次安装时继续抛出这个错误。它在模拟器上运行良好,但我不能对所有事情都使用模拟器。

我所尝试的:

  • 删除 Android Studio 配置文件。
  • 从项目中删除的 Gradle 文件。
  • 无效缓存和重置缓存。
  • 清理/重建项目。
  • 寻找类似的问题堆栈溢出(没有匹配我的问题)
  • 干净安装(删除所有文件,包括 SDK) Android Studio 3.5

更新

我在自己的机器上安装了 Linux Mint,并在那里测试了 AS 3.5,出于某种原因,甚至在 Android 7及以下设备上,一切都运行良好。

以前的操作系统: Windows 101903

当前操作系统: Linux Mint 19.2

我认为这个问题可能源于 Windows 机器。

91468 次浏览

At last, I found the solution

just set v2SigningEnabled true

 signingConfigs {
release {
v2SigningEnabled true
}
}

try to chang android:appComponentFactory="" to android:appComponentFactory="new","new" can be any words

Deleting/uninstalling the app from the device fixed the problem for me.

This issue in Android Studio happens for devices lower then API 26 (Android 8). This is caused by replacement of InstantRun, known now as ApplyChanges.

Seems to be there are only two ways before they fix it in the next update.

  1. Run on API>=26.
  2. After every change in code edit run configuration changing deploy from APK to App bundle and vise-versa. If I correctly understand, this will correctly rebuild app and workaround bug.

Of course, there is an option to manually delete app from device before running app from AndroidStudio.

I did not face the problem myself. However, previously we had some problems with the Instant Run of the Android Studio. I would like to suggest checking the following settings in your Android Studio and uncheck the settings to check if your code works now.

Go to the Android Studio -> Preference and then uncheck the following under the Deployments.

enter image description here

Here's what is new in Android Studio 3.5 regarding this which will help you to understand the feature better.

enter image description here

For me either uninstalling the app or cleaning project "solves" the problem. To make it less frustrating I added clean job to debug build type like so:

buildTypes {
...
debug {
clean
}
...
}

After reading the Release Notes regarding Apply Changes, I finally found a solution here: https://developer.android.com/studio/run#apply-changes-run-fallback

Enable Run fallback for Apply Changes

After you've clicked either Apply Changes and Restart Activity or Apply Code Changes, Android Studio builds a new APK and determines whether the changes can be applied. If the changes can't be applied and would cause Apply Changes to fail, Android Studio prompts you to Run Run icon your app again instead. However, if you don't want to be prompted every time this occurs, you can configure Android Studio to automatically rerun your app when changes can't be applied.

To enable this behavior, follow these steps:

  1. Open the Settings or Preferences dialog:
    • On Windows or Linux, select File > Settings from the menu bar.
    • On macOS, select Android Studio > Preferences from the menu bar.
  2. Navigate to Build, Execution, Deployment > Deployment.
  3. Select the checkboxes to enable automatic Run fallback for either of the Apply Changes actions.
  4. Click OK.

Screenshot running on Linux

I too am having this same problem after upgrading to 3.5. I was wondering if you have had any luck getting 'Run' to work with a connected device?

UPDATE: I was am to get this to work by Setting "APK from app bundle" under Installation Options in the "Run/Debug Configurations" dialog

Open Run/Debug Configuration dialog (Windows: Run > Edit Configurations)

edit You app > ABC0 > ABC1 > Install Flags .

add install flags -r -t.

This flags means adb install -r -t apkpath

screen pic

Finally, I got the solution in the code edit run configuration changing in Installation option DEPLOY--> from select 4th option -->(Nothing) option --> Apply And the app works properly in android studio 3.5. In mobile and emulator also. This work properly in android version 9 also This is a permanent solution.

Add a "clean" gradle task dependency before installing/running your apks using below configuration.

project.afterEvaluate {
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def capitalizedVariant = variant.name.capitalize()
def assembleVariantTask = project.tasks."assemble${capitalizedVariant}"
assembleVariantTask.dependsOn clean
}
}
}

Copy and paste above code into your app/build.gradle file, this works for all the build variants.

In specifically, above code will be equivalent to below if you only have debug and release build types:

assembleDebug.dependsOn clean
assembleRelease.dependsOn clean

Try to run the command "adb devices", if the output is empty, then reconnect the device. This helped me with the same error. Android studio 3.5 does not determine that the device has disconnected.

There is a problem with Lineage OS as stated by Google team in https://issuetracker.google.com/issues/139782879:

We are able to reproduce it on a device with LineageOS. It does not fully support a system call that we use for DeltaInstall.

There is no apparent solution (other than removing the APK from build folder or uninstalling the application).

We should have a workaround for it but as it stands right now, LineageOS will not have DeltaInstall and will always need to perform a slower full install.

Changing to Nothing as pointed out by OP will not deploy the APK to the device (that's why an error will not be displayed), so it will not solve the problem.

Edit:

This has been fixed in Android Studio 3.6.

Thanks for the feedback. This should be fixed in the latest versions of 3.6.

I got the solution in the code edit run configuration changing in Deploy select Default APK and install flag =-r -t and then Apply for the run. The app will run in all devices and emulator. I was testest in OPPO 1 plus, Samsung Tab, Emulator Also.

Please Go thought the Edit Run configuration near to run button in Android Studio

edit app > general ==> installation options ==> Install flags

add install flags -r -t

-r means "replace existing application". -t means "allow test packages"

enter image description here

It bug still have on my mac os, when i get new real device and try install apk from android studio 3.5 - and I find ugly way how it fix - open terminal in studio and follow:

cd app/build/outputs/apk/debug
adb install -r -t your_app_name.apk

And it need to do with each project and each device!!

Edited:

I eventually installed

Android Studio 3.6 Canary

  • it's more working version than 3.5

But stiil need add into install flags -r -t

What Worked for me to remove old application, then rerun the project. In that case old sign certificate does not bother.

You need disable "Use libusb backend" in preferences--> debugger enter image description here

I also got this error when I ran the application on real xiaomi pocophone 1 and solved this problem by running the application first on the emulator, and then on my xiaomi pocophone 1

splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a','x86_64'
universalApk true
}
}

Due to the different constructions such as 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', and 'arm64-v8a', we have to add the configuration above into build.gradle file.

I uninstalled the app from emulator, ran and everything went back to normal

For me minSdkVer = 22, tarSdkVer = 28,run Gradle -> app -> Tasks -> build -> clean && cleanBuildCache action, problem solved.

I pressed the hammer icon to rebuild the app then it installed. So I don't know? The whole android hack job platform sucks.

All that money yet google can't hire or find programmers good enough to come up with their own true operating system.

In my case, it only works by disabling the APK signature verification:

$ adb shell settings put global verifier_verify_adb_installs 0

And using the -r -t flags mentioned above

I also faced the same issue , i followed the following steps 1) Clean Project 2) Rebuilt Project

This solved my problem

In my case, I can't solve with all of the above answers so that I find another way. Finally, I found the solution. Just find the correct drivers of phone. My development phone is Samsung Galaxy Note 2 (MODEL : GT-N7105 / Android 4.1.2). I just share my solution to how I solved it. Hope save your time.

The problem occurs when you are testing a new module. First, you write it individually, and then add it to the main app. When you add it to the main app, delete your "test_app" from your phone.

Run -> Edit Configuration -> install flags: -r -t -> Apply -> Ok

gradle.properties -> android.enableAapt2=false

Build > Clean project its work's for me. Before change other setting try this first.

Happy coding :)

I got this problem a few minutes ago when I tried running my app on real device and stopped gradle build before it finished. What I just did was to uninstall the app on device and rerun the app on both AVD and real device (simultaneously) and it worked. Hope this works for you too

Main Solution

  1. File -> Settings -> Build, Execution, Deployment -> Debugger > Disable Use libusb backend

  2. Gradle (Flap to the right of the IDE) -> android -> app -> Tasks -> install -> uninstallAll or you can also do it by console in the following way:

    $ ./gradlew uninstallAll



Other Tips:

  • Delete and create the app again in Run/Debug Configuration

    • Installation Options -> Check Install for all users
  • Run/Debug Configuration -> Launch Options > Launch: Specified Activity > Choose an Activity

  • Install app using another physical device, version of the IDE or PC

  • Reinstall IDE and delete .android

  • Retry with the main solution


If you want to install and open the app you can use adb with the following commands:

$ adb install -r -t absolute-path.apk


$ adb shell am start -n "com.package.flavor.env/.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

GL

Source

1-clean project from Build -> CleanProject

2-delete folder outputs from ProjectPath/app/build/outputs

3-then build gradle and run app

For me the issue started when I created a new blank activity and Android studio created a Wearable activity for some reason. Once I removed all mentions to wearable activity from the manifest and I deleted the class everything went back to normal.

For me I added accidentally new BlankActivity which is inherited from Wearable Activity. Then I deleted the activity code and layout file. But I forgot to delete the wearable related tag in App Manifest.xml file. This is the main problem for someone like me.

I got this because the device was locked and required user to accept permissions in order to install it. (Huawei Harmony OS)

Unlocking the phone to prepare for the installation process solved the issue.

If your app targets Android 12 or higher, you must declare these attribution tags in your app's manifest file. If the app component includes the LAUNCHER category, set android:exported to true.

 <activity
android:name="com.test.activity.SplashActivity"
android:clearTaskOnLaunch="true"
android:label="@string/app_name"
android:launchMode="singleTop"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">

Also check receiver or service in Androidmanifest, if you are using any receiver or service set android:exported="true" or false according requirement.

<receiver
android:name="com.test.receiver.ShareReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.test.fcm.android.action.broadcast" />
</intent-filter>
</receiver>


<service
android:name="com.google.android.gms.tagmanager.InstallReferrerService"
android:exported="true" />

Also update all your gradle dependency. I have updated following dependency as per requirement.

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'




androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.razorpay:checkout:1.6.15'

Hope it will help you as well.