将设备从Android 8更新到9后无法从Android Studio启动应用

时间:2019-07-02 07:21:51

标签: java android android-studio launch android-9.0-pie

我认为问题已解决并标记了问题,因此我删除并重新发布了问题,但事实并非如此,我正在添加有关此问题的更多信息。

我正在使用Android应用程序,并且将设备的Android版本更新为9后,我再也无法从Android Studio运行应用程序了。

我在事件日志中看到两个不同的错误:

第一个(也是最短的):

  

会话“ app”:安装失败。安装失败

尝试了下一个链接中的所有内容,但没有运气:

Session 'app' error while installing APK

第二个:

  

断开的管道java.io.IOException:断开的管道位于   sun.nio.ch.FileDispatcherImpl.write0(本机方法)位于   sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)在   sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)在   sun.nio.ch.IOUtil.write(IOUtil.java:65)在   sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)在   com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:524)   在   com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:627)   在   com.android.ddmlib.SplitApkInstaller.uploadApk(SplitApkInstaller.java:133)   在   com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:73)   在com.android.ddmlib.Device.installPackages(Device.java:927)处   com.android.tools.deployer.AdbClient.install(AdbClient.java:75)位于   com.android.tools.deployer.ApkInstaller.install(ApkInstaller.java:32)   在com.android.tools.deployer.Deployer.install(Deployer.java:76)处   com.android.tools.idea.run.tasks.DeployTask.perform(DeployTask.java:79)   在   com.android.tools.idea.run.tasks.AbstractDeployTask.perform(AbstractDeployTask.java:109)   在   com.android.tools.idea.run.LaunchTaskRunner.run(LaunchTaskRunner.java:132)   在   com.intellij.openapi.progress.impl.CoreProgressManager $ TaskRunnable.run(CoreProgressManager.java:727)   在   com.intellij.openapi.progress.impl.CoreProgressManager.lambda $ runProcess $ 2(CoreProgressManager.java:164)   在   com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582)   在   com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)   在   com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)   在   com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:151)   在   com.intellij.openapi.progress.impl.CoreProgressManager $ 4.run(CoreProgressManager.java:403)   在java.util.concurrent.FutureTask.run(FutureTask.java:266)在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)   在   java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)   在java.lang.Thread.run(Thread.java:745)

     

我的设备是华为P20,我正在使用最新的Android Studio   在Android 8到9升级后,使用Ubuntu 3.4.1的应用和从An​​droid Studio运行的应用程序停止运行。

     

作为注释,我可以添加一下,构建过程可以正常运行并且可以检测到设备   启动时正确显示(在第一个屏幕中选择   目标设备),我也可以在logcat中看到该设备已连接   查看器,但是当完成构建时,准备部署时,您会听到   插入/拔出USB设备时计算机发出的声音

有帮助吗?

编辑1:

我认为这最终是一个OS(Ubuntu)问题,因为恢复了我的虚拟机的最近备份并且运行良好,但是在更新了Android Studio和SDK(如建议的那样)之后,它又开始出现故障,因此必须我认为,应该结合我的设备操作系统Android 9和最新的SDK更新。

在“失败”的虚拟机中,我可以在旧的Android 4手机和4.4.3 Asus平板电脑中运行该应用程序,而不是在新的Android 9中运行,这就是为什么我怀疑它可能与Android 9相关问题。

这是我的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>

这是我的build.gradle文件:

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'
}

编辑2:

试图运行另一个我正在运行的应用程序,并且在成功构建后以及何时要部署apk时出现此错误:

  

安装失败,并显示消息'cmd package install-create -r -t -S   11182369'返回错误'未知失败:安全异常:   权限被拒绝:pm命令中的runInstallCreate要求以   用户-1,但正在从用户0呼叫;这需要   android.permission.INTERACT_ACROSS_USERS_FULL   java.lang.SecurityException:权限拒绝:from的runInstallCreate   pm命令要求以用户-1的身份运行,但正在从用户0调用;这个   需要android.permission.INTERACT_ACROSS_USERS_FULL   com.android.server.am.UserController.handleIncomingUser(UserController.java:1827)   在   com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:25069)   在   android.app.ActivityManager.handleIncomingUser(ActivityManager.java:4848)   在   com.android.server.pm.PackageManagerShellCommand.translateUserId(PackageManagerShellCommand.java:2402)   在   com.android.server.pm.PackageManagerShellCommand.doCreateSession(PackageManagerShellCommand.java:2408)   在   com.android.server.pm.PackageManagerShellCommand.runInstallCreate(PackageManagerShellCommand.java:949)

1 个答案:

答案 0 :(得分:2)

这是一个奇怪的问题,已经在SO上进行了几次讨论,尤其是在新更新的Android 9设备上。

您是否尝试过禁用然后重新启用开发人员选项? (也许重新启动设备?)这似乎已经修复了一些问题。

如果这不起作用,您可能需要查看一下并从那里开始-

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