user7632135
user7632135

Reputation:

Android: Error while installing APKs

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>

Upvotes: 57

Views: 102831

Answers (18)

trinvh
trinvh

Reputation: 1580

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

Upvotes: 0

msayubi76
msayubi76

Reputation: 1658

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

Upvotes: 0

yusuf
yusuf

Reputation: 1263

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.

Upvotes: 0

Eshan Chattaraj
Eshan Chattaraj

Reputation: 368

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.

Upvotes: 1

JPZ
JPZ

Reputation: 1361

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.

Upvotes: 114

Ambilpura Sunil Kumar
Ambilpura Sunil Kumar

Reputation: 1463

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

Upvotes: -1

VAIBHAV NERLE
VAIBHAV NERLE

Reputation: 322

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

Upvotes: -1

ssowri1
ssowri1

Reputation: 1317

I used to Clean the project and fixed this issue.

Build -> Clean Project.

Upvotes: 2

Swapnil Akubattin
Swapnil Akubattin

Reputation: 3

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.

Upvotes: -1

happy_coding
happy_coding

Reputation: 1135

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

Upvotes: 5

Catalin
Catalin

Reputation: 119

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.

Upvotes: 1

Animesh Patra
Animesh Patra

Reputation: 852

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.

Upvotes: 54

arnav
arnav

Reputation: 61

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.

Upvotes: 0

GauRav MisHra
GauRav MisHra

Reputation: 21

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.

Upvotes: 2

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

Upvotes: 9

Smiles
Smiles

Reputation: 491

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!

Upvotes: 6

Mahesh Cheliya
Mahesh Cheliya

Reputation: 1364

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

Settings > Additional Settings > Developer Options > MIUI Optimization

Check Answer here

Upvotes: 9

alijandro
alijandro

Reputation: 12147

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.

Upvotes: 4

Related Questions