57

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

    <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>
Lucie P.
  • 603
  • 1
  • 5
  • 6

18 Answers18

114

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.

Peter
  • 437
  • 1
  • 4
  • 20
JPZ
  • 1,360
  • 1
  • 9
  • 14
  • i am using genymotion.other apps are working fine.But only app is not installing.The virtual device is android 8.0.error getting is error while installing apk – anju jo Oct 23 '18 at 07:25
  • Clean build and rebuild fixed the issue with installing apk failure. Thank you! – Agent 0 Jan 01 '19 at 00:31
  • Thank you! Following those steps now I am able to build and use instant run functions. That was the problem, caching. Thanks! – wilmerlpr Jan 31 '19 at 07:46
  • In my case it was the phone's poor memory. I freed up space and it worked.If it can be of use to someone .. – Bogojob Mar 18 '19 at 19:04
  • where can i find "Instant Run" feature / option? – Kamlesh Oct 23 '19 at 06:13
  • Thanks @Bogojob - this was the issue for me as well :) clearing up some memory fixed it – eh21 Oct 21 '20 at 08:20
54

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

  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".

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.
Anže Mur
  • 1,545
  • 2
  • 18
  • 37
Animesh Patra
  • 852
  • 8
  • 14
  • 7
    This solved the problem for me, the original error message in Android Studio was `Unknown failure (at android.os.Binder.execTransact(Binder.java:565)` – Yoav Feuerstein Oct 22 '17 at 09:13
  • 1
    I try the first and second answer, then saw android studio shows that my emulator device internal size is not enough, I resize and reboot the device, now it works. – Sarah0050 Oct 09 '18 at 09:17
9

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

Settings > Additional Settings > Developer Options > MIUI Optimization

Check Answer here

Mahesh Cheliya
  • 1,334
  • 1
  • 16
  • 21
9

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

  • In my case, I just zipped the existing project without deleting the `build` folder and copied it to a different laptop and executed it to the emulator and it happened. I just executed `clean` like this answer and everything works fine now. – wonsuc Dec 14 '18 at 12:28
6

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!

Smiles
  • 481
  • 1
  • 6
  • 15
5

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 :)

happy_coding
  • 1,064
  • 1
  • 13
  • 24
4

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.

alijandro
  • 11,627
  • 2
  • 58
  • 74
2

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.

2

I used to Clean the project and fixed this issue.

Build -> Clean Project.

ssowri1
  • 1,299
  • 2
  • 14
  • 31
1

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.

Catalin
  • 109
  • 1
  • 2
1

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.
Eshan Chattaraj
  • 368
  • 1
  • 6
  • 19
0

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.

arnav
  • 51
  • 5
0

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.

yusuf
  • 1,233
  • 1
  • 15
  • 29
0

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
msayubi76
  • 1,446
  • 1
  • 12
  • 18
0

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

trinvh
  • 1,500
  • 2
  • 11
  • 20
-1

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.

Agilanbu
  • 2,747
  • 2
  • 28
  • 33
  • try to highlight the keywords and be clear with the format it will help to reach out your answer for others – Agilanbu Jan 31 '19 at 09:41
-1

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

VAIBHAV NERLE
  • 322
  • 2
  • 12
-1

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