Android: Error while installing APKs

JavaAndroidAndroid StudioFailed Installation

Java Problem Overview


I'm slowly trying to do some simple tasks in Android Studio. The following app is installed on emulator without any errors. But when I tried to install it on a real device Redmi 3S this error occured:

Unknown failure (Failure - not installed for 0)
Error while Installing APKs

I went through similar questions around here but in these cases the error was caused by not enabled debugging, or not accepitng the app instalation. However, I allowed debugging and I also tried to install some other app in Studio and it worked fine.

So the question probably is, what's wrong with the code.

>MainActivity.java

package tlacitko.button;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void sendMessage(View view) {
        new Thread(new Runnable() {
            public void run() {

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try{
                            URL url = new URL("http://147.32.186.51:8080");
                           // HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                            InputStream is = url.openStream();
                            BufferedReader br = new BufferedReader(new
                                    InputStreamReader(is));
                            String s = "";
                        }catch(MalformedURLException ex){

                        }catch(IOException e){
                        }
                    }
                });
            }
        }).start();
    }
}

And the xml code: >activity_main.xml http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="tlacitko.button.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Try to connect the server."
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="7dp"
        android:layout_marginTop="16dp"
        android:onClick="sendMessage"
        android:text="Conncect"
        app:layout_constraintLeft_toRightOf="@+id/editText"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</android.support.constraint.ConstraintLayout>

Java Solutions


Solution 1 - Java

Follow these steps to overcome the issue.

  1. Disconnect all devices connected to system, and close all emulators running on System.
  2. Turn off Instant Run feature from settings.
  3. Perform a clean build.
  4. Turn on Instant Run feature from settings.
  5. Perform a clean build.
  6. Connect your device/start your emulator and ensure it is online.
  7. Run the project by selecting the device/emulator.

Note:

  1. You should not have different instances of Android Debug Bridge(adb) running on system.

  2. If using Genymotion then make sure that you use the custom sdk path mentioned in the Genymotion settings the which you mentioned in the settings of Android Studio.

These steps are likely to solve your issue, however it may also be a problem with android versions.

Solution 2 - Java

Turn off the Instant Run in Android Studio. Follow the steps below:

> File >> Settings >> Build, Execution, Deployment.

  1. Click on Instant Run and unckeck "Enable Instant Run to hot swap code/resource changes on deploy".

  2. Click on "Apply" and "OK".

Try running the application again. It should install the app now. You can re enable Instant Run again anytime.

EDIT (Android Studio 3.0)

Disable Instant Run (Android Document)

To disable Instant Run:

  1. Open the Settings or Preferences dialog. (For Mac, Android Studio -> Preferences)
  2. Navigate to Build, Execution, Deployment > Instant Run.
  3. Uncheck the box next to Enable Instant Run.

Solution 3 - Java

For Redmi and Mi devices turn off MIUI Optimization and reboot your phone.

Settings > Additional Settings > Developer Options > MIUI Optimization

Check Answer here

Solution 4 - Java

For me I just made a clean for the App then everything works fine.

Solution 5 - Java

I'm now faced with this problem, I have already uninstalled the apk, now I use Android Studio 3.0 want to run apk to Xiaomi MIX 2(Android 7.1.1, API 25), but it failed.

$ adb shell pm install -t -r "/data/local/tmp/com.package"
Failure [INSTALL_FAILED_USER_RESTRICTED: Install canceled by user]

And Android Studio tells me "It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing." but I've uninstalled this apk.

Android Studio popup info

And I click "OK" button, but it also failed.

$ adb shell pm uninstall com.package
Unknown failure (at android.os.Binder.execTransact(Binder.java:565))
Error while Installing APK

And finally I find how to solve this problem, I don't turn on "Verify apps over USB", because now this device cannot turn on it until you login xiaomi account, and this is a new device that has not been logged in.

Step 1: Go to “Setting” → find “Developer options” in System, and click.

Step 2: TURN ON “Verify apps over USB” in Debbuging section.

Step 3: Try “Run app” in Android Studio again!

Solution 6 - Java

Before try all the above suggestion, check enough memory space available in device. This will also reason this problem.

> Error: android.os.ParcelableException: java.io.IOException: Requested internal only, but not enough space

Happy coding :)

Solution 7 - Java

It might be the compatibility with Xiaomi devices for Android studio version 2.3 and gradle plugin version 2.3.0 with instant run on.

adb multiple-install the splited apks return error.

You can turn off instant run, or in Settings -> Developer options, toggle Turn on MIUI optimization off if you want instant run also.

Solution 8 - Java

It may be your device storage is full. If you are testing on a physical device. However, if you are testing in Emulator then check there also that storage space is available or not. Otherwise, you have to turn-off the Instant Run.

Solution 9 - Java

I used to Clean the project and fixed this issue.

Build -> Clean Project.

Solution 10 - Java

I had the same problem but my issue was lack of space on the device.

Try this On your device go to Settings -> Device maintenance -> Optimise now

Once that is done, try again.

Solution 11 - Java

You can follow this step for rechecking Instant Run:

  1. File >> Settings >> Build, Execution, Deployment.
  2. Click on Instant Run and unckeck "Enable Instant Run to hot swap code/resource changes on deploy".
  3. Click on "Apply" and "OK".

But Sometimes Rechecking Does Not work.

That Time You need to temporarily disable your AntiVirus and Windows Defender if you run your Deployment in WIN PC

Follow this steps:

  1. Disable your Antivirus or Windows Defender for 15/30min
  2. Perform a clean build.
  3. Rebuild Project
  4. Run the Project to your Emulator or in your Devices

Note:

  • \app\build\intermediates\split-apk\debug\slices\slice_5.apk get some malware Affected.

Solution 12 - Java

I also experienced the same issue when I was installing an app in a new device. This error usually occurs when the app installation is not allowed by the os. This might be because you might not have the authorization to install the app on your phone from just any source.

So try checking the allow install apps via usb in developer options. If this doesn't work then try revoking all the usb debugging authorizations and then try installing and provide permission when asked.

If this also doesn't cut it try disabling instant run as explained in one of the answers above.

Solution 13 - Java

You can try to delete all your applications on the device.

I am using Android Emulator, I deleted my apps via; Settings > Apps & notifications > select your app > uninstall.

Solution 14 - Java

This issue often comes due to these two reasons.

  1. when you have less storage on your device

  2. your device not connected properly with android studio

Solution 15 - Java

I've managed to fix "com.android.ddmlib.InstallException: Unknown failure: cmd: Failure calling service package: Failed transaction" error by just disabling selinux.

Use JuiceSSH or Temux to access the local device's shell, then run:

setenforce 0

No need to disable MIUI Optimization

Solution 16 - Java

Turn off the Instant Run in Android Studio. Follow the steps below:

  • For Old Version of Android Studio (Version < Android Studio 3.0) File >> Settings >> Build, Execution, Deployment.

  • Click on Instant Run and Unckeck all Enable Instant Run to hot swap code/resource changes on deploy.

  • Click on Apply and OK.

  • Try running the application again. It should install the app now. You can re enable Instant Run again anytime.

  • For New (Android Studio 3.0) Disable Instant Run (By Default)

To disable Instant Run:

  • Open the Settings or Preferences dialog. (For Mac, Android Studio -> Preferences)

  • Navigate to Build, Execution, Deployment > Instant Run.

  • Uncheck the box next to Enable Instant Run.

  • Clean Project and try running the application again. It should install the app now. You can re enable Instant Run again anytime.

Solution 17 - Java

Disconnect the divice from system and in Android studio Go to File ->Invalidate Cache and/Restart. It Works....

Solution 18 - Java

Simple and straight Answer...

Uncheck Instant Run as follow...

Step: file>>Settings>>Build,Execution,Deployment>>uncheck Enable Instant Run to hot swap code/resource changes on deploy(default enabled). enter image description here

Step 2: Apply and Click On Ok enter image description here

Step 3: Run the project...

Work For Sure....@Ambilpura

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLucie P.View Question on Stackoverflow
Solution 1 - JavaJPZView Answer on Stackoverflow
Solution 2 - JavaAnimesh PatraView Answer on Stackoverflow
Solution 3 - JavaMahesh CheliyaView Answer on Stackoverflow
Solution 4 - JavaMohammed Salim Al-OthmanView Answer on Stackoverflow
Solution 5 - JavaSmilesView Answer on Stackoverflow
Solution 6 - Javahappy_codingView Answer on Stackoverflow
Solution 7 - JavaalijandroView Answer on Stackoverflow
Solution 8 - JavaGauRav MisHraView Answer on Stackoverflow
Solution 9 - Javassowri1View Answer on Stackoverflow
Solution 10 - JavaCatalinView Answer on Stackoverflow
Solution 11 - JavaEshan ChattarajView Answer on Stackoverflow
Solution 12 - JavaarnavView Answer on Stackoverflow
Solution 13 - JavayusufView Answer on Stackoverflow
Solution 14 - Javamsayubi76View Answer on Stackoverflow
Solution 15 - JavatrinvhView Answer on Stackoverflow
Solution 16 - JavaSwapnil AkubattinView Answer on Stackoverflow
Solution 17 - JavaVAIBHAV NERLEView Answer on Stackoverflow
Solution 18 - JavaAmbilpura Sunil KumarView Answer on Stackoverflow