-1

Still not being able to solve this annoying issue. I'm working on an Android app, and after updating OS to Android 9 app launch from Android Studio stopped working.

After building successfully, when AS is about to deploy Android Studio pops up an alert with next message:

Installation failed because the device "huawei-sne_lx1-HYF0218911000087" disconnected.

And in the Event Log window I see the following error:

Broken pipe java.io.IOException: Broken pipe at 
sun.nio.ch.FileDispatcherImpl.write0(Native Method) at 
sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) at 
sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) at 
sun.nio.ch.IOUtil.write(IOUtil.java:65) at 
sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471) at 
com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:524) at 
com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:627) at
com.android.ddmlib.SplitApkInstaller.uploadApk(SplitApkInstaller.java:133) at 
com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:73) at 
com.android.ddmlib.Device.installPackages(Device.java:927) at 
com.android.tools.idea.run.tasks.SplitApkDeployTask$SplitApkInstaller.installApp(SplitApkDeployTask.java:142) at 
com.android.tools.idea.run.RetryingInstaller.install(RetryingInstaller.java:93) at 
com.android.tools.idea.run.tasks.SplitApkDeployTask.perform(SplitApkDeployTask.java:106) at 
com.android.tools.idea.run.LaunchTaskRunner.run(LaunchTaskRunner.java:132) at 
com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:727) at 
com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:164) at 
com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582) at 
com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532) at 
com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87) at 
com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:151) at 
com.intellij.openapi.progress.impl.CoreProgressManager$4.run(CoreProgressManager.java:403) at 
com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314) at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at 
java.util.concurrent.FutureTask.run(FutureTask.java:266) at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at 
java.lang.Thread.run(Thread.java:745)

I've already checked this:

Android Pie - 9 (API 28) : Installing APK .... not successfully installing

and this:

Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL

and come up with a way to solve the problem, but something that is definitely not a solution, to change my applicationId.

Strangely, if I change appId then the app launches just fine, but this is clearly not a solution as I don't want (and can't) change appId so I need help to find a real solution.

I tried all suggestions in those links, like restarting the device, disabling and re-enabling developer options and so, but no diference, app only starts running again from Android Studio if I change appId.

My Android Studio as well as SDKs are up to date and I'm working under Ubuntu.

Any ideas?

Edit 1: Adding AndroidManifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.xxx.xxx"
          android:versionCode="1"
          android:versionName="1.0">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

    <application
        android:name=".activities.shared.AppSettings"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/Theme.myTheme.TitleBar">
        <service
            android:name=".activities.shared.OnClearFromRecentService"
            android:stopWithTask="false"
            android:enabled="true"
            android:exported="true">
        </service>

        <provider
            android:name=".activities.shared.GenericFileProvider"
            android:authorities="${applicationId}.xxx.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>

        <activity
            android:name=".activities.launch.SplashActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.main.MainActivity"
            android:configChanges="orientation"
            android:parentActivityName=".activities.launch.SplashActivity">
        </activity>
        <activity
            android:name=".activities.about.AboutUsActivity"
            android:parentActivityName=".activities.main.MainActivity">
        </activity>
        <activity
            android:name=".activities.about.ChangeLogActivity"
            android:parentActivityName=".activities.about.AboutUsActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.xxx.xxx.activities.about.AboutUsActivity"/>
        </activity>
        <activity
            android:name=".activities.about.ReportProblemActivity"
            android:parentActivityName=".activities.about.AboutUsActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.xxx.xxx.activities.about.AboutUsActivity"/>
        </activity>
        <activity
            android:name=".activities.main.HowToUseActivity"
            android:parentActivityName=".activities.main.MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.xxx.xxx.activities.main.MainActivity"/>
        </activity>
        <activity
            android:name=".activities.DisplayThoughtActivity"
            android:parentActivityName=".activities.main.MainActivity">
        </activity>
        <activity
            android:name=".activities.shared.SettingsActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="Settings">
        </activity>

        <receiver android:name=".helpers.notification.AlarmTakeTestReceiver"/>
    </application>

</manifest>

Edit 2: Adding app build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        //versioning
        //classpath 'org.moallemi.gradle.advanced-build-version:gradle-plugin:1.5.3'
    }
}

//apply plugin: 'org.moallemi.advanced-build-version'

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
        maven { url 'https://repository-achartengine.forge.cloudbees.com/snapshot/' }
        maven { url 'def androidHome = System.getenv("ANDROID_HOME")' }
        maven { url "/Home/Diego/Android/Sdk/extras/android/m2repository/" }
        google()
    }
}

/*advancedVersioning {
    nameOptions { }
    codeOptions {
        versionCodeType org.moallemi.gradle.internal.VersionCodeType.AUTO_INCREMENT_ONE_STEP
        dependsOnTasks 'debug', 'release', 'assemble'
    }
    outputOptions { }
}

def appVersionName = advancedVersioning.versionName
def appVersionCode = advancedVersioning.versionCode*/

Edit 3:

As extra info, I have another app I'm working on that runs fine; i uninstalled it and was able to launch it again from Android Studio with no problems, so I guess it is something related specifically to this app, but cannot figure out what.

BTW, I already cleaned project to no avail.

Edit 4:

To add more weird things, if I run the app on an older Android 5 device it runs just fine, so I'm so confused :s

Edit 4: Adding build.gradle file

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    buildToolsVersion '29.0.0'
    def code
    Properties versionProps = new Properties()
    def versionPropsFile = file('version.properties')
    if (versionPropsFile.exists())
        versionProps.load(new FileInputStream(versionPropsFile))
    code = (versionProps['VERSION_CODE'] ?: "0").toInteger() + 1
    versionProps['VERSION_CODE'] = code.toString()
    versionProps.store(versionPropsFile.newWriter(), null)
    packagingOptions {
        pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
    }
    defaultConfig {
        applicationId 'com.xxx.xxx'
        minSdkVersion 17
        targetSdkVersion 28
        versionCode code
        versionName "1.0." + code
        multiDexEnabled true
        compileOptions {
            sourceCompatibility java_version
            targetCompatibility java_version
        }
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
    compileOptions {
        sourceCompatibility java_version
        targetCompatibility java_version
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    project.ext { appName = 'xxx' }
                    def newName = 'xxx.apk'
                    outputFileName = new File("./build/", newName)
                }
            }
        }
        debug {
        }
    }
    allprojects {
        repositories {
            jcenter()
            mavenCentral()
            def androidHome = System.getenv("ANDROID_HOME")
            maven {
                url "$androidHome/extras/android/m2repository/"
            }
            maven {
                url "https://maven.java.net/content/groups/public/"
            }
        }
    }
    productFlavors {
    }
}

dependencies {
    //Google Guava
    api 'com.google.guava:guava:28.0-jre'
    //writingminds
    api 'com.writingminds:FFmpegAndroid:0.3.2'
    //JavaCV video
    api group: 'org.bytedeco', name: 'javacv', version: '1.5.1'
    //api group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '4.1-1.4.4', classifier: 'android-arm'
    //api group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '4.0.1-1.4.4', classifier: 'android-arm'
    //volley
    api 'com.android.volley:volley:1.1.1'
    //spotify
    api 'com.github.kaaes:spotify-web-api-android:0.4.1'
    //mail API 19
    //api 'com.sun.mail:android-mail:1.6.3'
    //api 'com.sun.mail:android-activation:1.6.3'
    //mail API 16
    api 'com.sun.mail:android-mail:1.6.3'
    api 'com.sun.mail:android-activation:1.6.3'
    //apache commons lang
    api 'org.apache.commons:commons-lang3:3.9'
    //Font Selector List Preference
    api 'com.vanniktech:vntfontlistpreference:1.0.0'
    //Rate my app
    api 'com.github.hotchemi:android-rate:1.0.1'
    //Support
    api 'com.android.support:appcompat-v7:28.0.0'
    api 'com.android.support:support-v4:28.0.0'
    /*api 'com.android.support:support-v4:28.0.0'
    api 'com.android.support:appcompat-v7:28.0.0'
    api 'com.android.support:cardview-v7:28.0.0'
    api 'com.android.support:recyclerview-v7:28.0.0'
    api 'com.android.support:customtabs:28.0.0'
    api 'com.android.support:support-annotations:28.0.0'*/
    //multidex
    api 'com.android.support:multidex:1.0.3'
    //AlertDialog
    implementation 'com.github.d-max:spots-dialog:1.1@aar'
    //glide animated gifs
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
Diego Perez
  • 2,188
  • 2
  • 30
  • 58
  • Can you post the error that comes under the log view, also try running adb command to see if your can see this device – Aniruddha K.M Jul 15 '19 at 18:57
  • Hi @war_Hero and thanks for replying, adb command shows the next: "List of devices attached: HYF0218911000087 device" so I guess it's working, and what do you mean with "log view"? Are you referring to LogCat window? – Diego Perez Jul 15 '19 at 19:03
  • Whenever the installation fails Android studio shows it in a log view, that one, also can you post your manifest and device os version – Aniruddha K.M Jul 15 '19 at 19:06
  • What you ask for is on my post, the Event Log message @war_Hero. My OS version is Huawei EMUI 9.0.1 and I'll edit post with Manifest file. – Diego Perez Jul 15 '19 at 19:15
  • Do you have any other flavor or same apk already installed in the device, can you post app build. gradle as well – Aniruddha K.M Jul 15 '19 at 19:18
  • Thanks again @war_Hero, no other apk installed and added app build.gradle to post. – Diego Perez Jul 15 '19 at 19:27
  • Added extra info @war_Hero. – Diego Perez Jul 15 '19 at 19:42

1 Answers1

0

If you haven't already, go to File->Project Structure, click on modules, then app. Check the Default Config and Properties tab, and check anythin that includes "Version". Make sure they are compatible with Android 9. I'm assuming you have developer mode and USB debugging enabled on your phone, but you might want to check anyway.

In project structure, go to module->app.

Community
  • 1
  • 1
willbill
  • 80
  • 1
  • 9
  • 1
    Also could you add the other build.gradle file? – willbill Jul 17 '19 at 18:37
  • Hello @William Li, and thank you very much for your help. It's completely nonsense, but followed your directions and went to project structure to see that in "Source Compatibility" and "Target Compatibility" $JavaVersion.VERSION_1_8 (Unnresolved reference $JavaVersion.VERSION_1_8) text was displayed, so I clicked the dropdown and selected the last item "1.8 (Java 8)" and after that a second strange thing happened, in build.gradle JavaVersion.VERSION_1_8 appeared between single quotes and project was not syncing, after removed singled quotes (maybe Android Studio bug?) project synced and... – Diego Perez Jul 17 '19 at 19:32
  • VOILÁ, app have run successfully, but... if I go to project structure I see the same reference error again and have to repeat all the steps to be able to launch the app again. I'm starting to see the light at the end of the tunnel because now there is a way to launch the app successfully, but this "java thing" is so weird and confusing :s ... It's just crazy if you have to do all this steps every time you launch the app. – Diego Perez Jul 17 '19 at 19:33
  • OK, I think I've found a solution, the most unexpected (and weird) solution here: https://stackoverflow.com/questions/53051923/unresolved-reference-javaversion-version-1-8 – Diego Perez Jul 17 '19 at 21:32
  • Still need to test it a little bit more, but I'll mark your answer as correct @William Li as you pointed me in the right direction :) – Diego Perez Jul 17 '19 at 21:33
  • Definitely weird, the solution explained in the link I've posted above (related to whatever any other issue is) worked two times and now I'm again at the beginning, not working with same "Disconnected" error. What I did is to close and reopen project and I was able to launch it, but only once, then closed and reopened project to no avail, like if it were something random ... everything's so weird... – Diego Perez Jul 17 '19 at 22:12
  • Now it won't launch even changind appId, I give up for now. – Diego Perez Jul 17 '19 at 22:36
  • It's completely nonsense, I have another Android app I'm working on and it can be launched from Android Studio with no problems. I feel so lonely in this :( – Diego Perez Jul 18 '19 at 18:44
  • It's so so weird that I cleaned project and after that app launched fine, restarted Android Studio and app is failing again with annoying "Device Disconnected" message. Definitely a random behaviour I'm not being able to understand :s – Diego Perez Jul 18 '19 at 18:58
  • Puf... updated Gradle from 4.4.1 to 5.5.1 still no luck. – Diego Perez Jul 18 '19 at 21:15
  • Disabled "Instant Run" in Settings and app started fine but... reboted Ubuntu/open Android Studio again and... "Over and ooover agaaaaain"... app its not running with error "ession 'app': Install failed". This is so incredible :((( – Diego Perez Jul 18 '19 at 21:54
  • Ok, for the first time my other app failed with same error, so now I can conclude it is not a problem with the app. I'm starting to guess the culprit was an Android Studio installation, maybe I should try to downgrade Android Studio, but most likely my app won't run because of incompatibilities with older AS versions. – Diego Perez Jul 18 '19 at 22:00
  • Can you tell which line of the app it's coming from? Also can you post the other build.gradle and the MainActivity.java? – willbill Jul 19 '19 at 05:03
  • I'm not sure, but most errors have a "FATAL ERROR" somewhere in the logcat. – willbill Jul 19 '19 at 05:05
  • Hi @William Li, thanks, I'm desperate with this. Added build.gradle as you asked for, and the app is not failing in one specific line as the phone apparently get's disconnected before the app (apk) is deployed. – Diego Perez Jul 21 '19 at 16:51
  • Completely nonsense, but's definitely random issue :((( ... Just a couple of minutes ago I was able to launch app from Android Studio, restarted AS and re-launched and this error is displayed when about to deploy APK: Session 'app': Install failed. Installation failed Rerun – Diego Perez Jul 21 '19 at 17:00
  • I've tried with my girlfriend Samsung Android 9 phone and it's apparently working fine, at least three attempts and app launched just fine, then switched to mine and failed at the first run :((( – Diego Perez Jul 21 '19 at 21:06