Reputation:
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
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
Reputation: 1658
This issue often comes due to these two reasons.
Upvotes: 0
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
Reputation: 368
You can follow this step for rechecking Instant Run:
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:
Note:
Upvotes: 1
Reputation: 1361
Follow these steps to overcome the issue.
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
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).
Step 3: Run the project...
Work For Sure....@Ambilpura
Upvotes: -1
Reputation: 322
Disconnect the divice from system and in Android studio Go to File ->Invalidate Cache and/Restart. It Works....
Upvotes: -1
Reputation: 1317
I used to Clean the project and fixed this issue.
Build -> Clean Project.
Upvotes: 2
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
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
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
Reputation: 852
Turn off the Instant Run in Android Studio. Follow the steps below:
File >> Settings >> Build, Execution, Deployment.
Click on Instant Run and unckeck "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.
Disable Instant Run (Android Document)
To disable Instant Run:
Upvotes: 54
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
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
Reputation: 790
For me I just made a clean for the App then everything works fine.
Upvotes: 9
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.
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
Reputation: 1364
For Redmi and Mi devices turn off MIUI Optimization and reboot your phone.
Settings > Additional Settings > Developer Options > MIUI Optimization
Upvotes: 9
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