Android studio fail to install app on device

2019-09-09 17:32发布

问题:

I have a Samsung Galaxy S5 device running Android 4.4.2 it was working just fine until a few weeks a go I started getting this issue, Android Studio fail to install the app after I press run and build the gradle

Additional information : I tried to run the app on an emulatir the first time it work and after I did some changes I tried to run on the emulator again but the changes were noy applied

This is the gradle file :

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.incorp.anisvikernes.appex"
    minSdkVersion 19
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:cardview-v7:23.1.0'
} 

This is the LogCat :

03:49:45 Executing tasks: [clean, :app:generateDebugSources,       :app:generateDebugAndroidTestSources, :app:prepareDebugUnitTestDependencies, :app:mockableAndroidJar, :app:compileDebugSources, :app:compileDebugAndroidTestSources, :app:compileDebugUnitTestSources]
03:51:04 Gradle build finished in 1m 18s 412ms
05:23:54 Executing tasks: [:app:assembleDebug]
05:28:19 Gradle build finished in 4m 25s 153ms
05:28:32 Error during Sync: An existing connection was forcibly closed by the remote host
05:28:32 Session 'app': Error Installing APK

This is the error

08/20 05:28:26: Launching app
$ adb push D:\projects\appex\app\build\outputs\apk\app-debug.apk   /data/local/tmp/com.incorp.anisvikernes.appex
java.io.IOException: An existing connection was forcibly closed by the remote host
Error while Installing APK

回答1:

I solved the same issue by

1. Disable USB debugging and developer options
2. Disconnect the device from USB 
3. Re enable USB debugging and developer options
4. Reconnect device 

Some said at the time I had the problem killing and restarting the adb worked.



回答2:

I actually found a solution that fixed this problem, it will seem really odd and wierd but after updating my driver (Win key+x -> device manager -> going to my device and pressing update button) I changed the USB cable used to connect the phone to my PC and it worked immediately



回答3:

After hours of no success, removing the USB-Extension cable worked for me. Anything worked with the usb-extension cable except the Installing APK process as you described. Maybe others can fix it to by changing the USB-cable to a short, stable working cable.