4

I deleted and reposted my question as I thought it was resolved and marked it, but it was not, and I'm adding much more info about it.

I'm working on an Android app and after updating my device's Android version to 9 I'm not being able to run my app from Android Studio anymore.

I'm seeing two different errors in Event Log:

The first (and shortest):

Session 'app': Install failed. Installation failed

Tried everything from next link with no luck:

Session 'app' error while installing APK

The second:

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.deployer.AdbClient.install(AdbClient.java:75) at com.android.tools.deployer.ApkInstaller.install(ApkInstaller.java:32) at com.android.tools.deployer.Deployer.install(Deployer.java:76) at com.android.tools.idea.run.tasks.DeployTask.perform(DeployTask.java:79) at com.android.tools.idea.run.tasks.AbstractDeployTask.perform(AbstractDeployTask.java:109) 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 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)

My device is a Huawei P20 and I'm working with latest Android Studio 3.4.1 with Ubuntu, and app run (launch) from Android Studio stopped working after Android 8 to 9 update.

As a note I can add that build process runs OK and device is detected correctly when launching (in the first screen where you select the target device) and I can also see device as connected in logcat viewer, but when finishing building, when ready to deploy you hear the sound that the computer does when plugging / unplugging an usb device

.

Any help?

Edit 1:

I thought it ended up being an OS (Ubuntu) problem, because restored a recent backup of my virtual machine and it was working fine, but after updating Android Studio and SDKs (as suggested) it started failing again so it has to be something in conjunction between my device OS Android 9 and the latest SDK updates, I presume.

In the "failing" vm I can run the app in an old Android 4 phone and in my 4.4.3 Asus tablet, and not in my new Android 9 one, and that's why I gussed it could be an Android 9 related issue.

This is my AndroidManifest.xml

<?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}.testMe.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>

This is my 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 JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    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 JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    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)
                    //def newName = output.outputFile.name //output.packageApplication.outputFile
                    //newName = newName.replace("app-", "$project.ext.appName-")
                    //newName = newName.replace("-release", "")
                }
            }
        }
        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-android'
    //writingminds
    api 'com.writingminds:FFmpegAndroid:0.3.2'
    //JavaCV video
    api group: 'org.bytedeco', name: 'javacv', version: '1.5'
    //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.5.6'
    api 'com.sun.mail:android-activation:1.5.6'
    //apache commons lang
    api 'org.apache.commons:commons-lang3:3.8.1'
    //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'
}

Edit 2:

Tried to run another of my working apps and I got this error after building successfully and when about to deploy apk:

Installation failed with message 'cmd package install-create -r -t -S 11182369' returns error 'Unknown failure: Security exception: Permission Denial: runInstallCreate from pm command asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL java.lang.SecurityException: Permission Denial: runInstallCreate from pm command asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL at com.android.server.am.UserController.handleIncomingUser(UserController.java:1827) at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:25069) at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:4848) at com.android.server.pm.PackageManagerShellCommand.translateUserId(PackageManagerShellCommand.java:2402) at com.android.server.pm.PackageManagerShellCommand.doCreateSession(PackageManagerShellCommand.java:2408) at com.android.server.pm.PackageManagerShellCommand.runInstallCreate(PackageManagerShellCommand.java:949)

Diego Perez
  • 2,188
  • 2
  • 30
  • 58

1 Answers1

3

It is a strange problem that has been discussed on SO a few times, happens particularly for devices newly updated Android 9.

Have you tried disabling and then re-enabling developer options? (And maybe restarting the device?) That seems to have fixed it for some.

If that doesn't work, you might want to look at these and go from there -

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

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

Vinay W
  • 9,912
  • 8
  • 41
  • 47
  • Thank you very much @Vinay Wadhwa, I appreciate your help. I disabled and re-enabled developer options several times and rebooted the phone, but I'll check the other two links you posted as soon as I'm back from work and let you know. I truly hope they'll help, as I'm almost desperate with this issue. – Diego Perez Jul 02 '19 at 10:53
  • You are welcome. Let us know how it works out for you. – Vinay W Jul 02 '19 at 10:54
  • Dear @Vinay Wadhwa you are the guy! Checking the first link was enough. One of the suggestions -between so many ones- was to rename applicationId in gradle, and that was the key to solve my problem. Still a weird problem, but spent a lot of time on it, so I turn the page now as I need a rest. Thank you really very much. – Diego Perez Jul 02 '19 at 18:33
  • I unmarked the question as correct (marked it as correct yesterday) because I have hurried to answer, but it's not resolved @Vinay Wadhwa. The suggestion of changing applicationId works, but it's not a real solution, as one of my apps is already published on Google Play and I can't (and don't want to) modify it's appId so... Now that we know appId "is the culprit", what else to try? – Diego Perez Jul 03 '19 at 09:40