为什么Android Studio 3.0.0在APK上设置FLAG_TEST_ONLY? [英] Why is Android Studio 3.0.0 setting FLAG_TEST_ONLY on APKs?

查看:162
本文介绍了为什么Android Studio 3.0.0在APK上设置FLAG_TEST_ONLY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过3.0.0-rcX(来自Canary渠道)到达了Android Studio 3.0.0(来自稳定渠道).

I have arrived at Android Studio 3.0.0 (from the stable channel) via 3.0.0-rcX (from the Canary channel).

当我启动一个全新的应用程序并对其进行构建时,以下代码(在应用程序内部)显示设置了FLAG_TEST_ONLY标志.

When I start a brand new app and build it, the following code (inside the app) shows that the FLAG_TEST_ONLY flag is set.

Log.e(TAG, "ApplicationInfo: " + (getApplicationInfo().flags & ApplicationInfo.FLAG_TEST_ONLY));

10-31 09:54:05.226 16129-16129/com.example.dummy E/MainActivity: ApplicationInfo: 256

该应用的清单是:

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

该标志阻止设备策略控制器安装它:

The flag stops Device Policy Controllers from being able to install it: Upgrading app in background using Device Policy Controller

为什么设置此标志,以及如何阻止其设置?

Why is this flag set, and how to I stop it from being set?

推荐答案

前几天,我遇到了麻烦.根据我的测试,仅当您从Android Studio运行该应用程序时,才会添加此标志.不幸的是,APK文件名不能提示问题.而且,尽管有文档说明,但该APK仅可在Android Studio中使用 .我专门试图通过adb安装它,该应该可以,但不能.

I ran headlong into this the other day. Based on my testing, this flag is added only if you run the app from Android Studio. Unfortunately, the APK filename doesn't hint at the problem. And, despite the documentation, this APK is only usable from Android Studio — I specifically was trying to install it via adb, which is supposed to work, but doesn't.

如果您以其他方式构建APK,则不应添加该标志.具体来说,我使用了assembleRelease Gradle任务.我希望Android Studio中的构建APK"菜单选项也能正常工作.

If you build the APK in other ways, the flag should not be added. Specifically, I used the assembleRelease Gradle task. I would expect the "Build APK(s)" menu option in Android Studio to work as well.

鉴于Instant Studio和Android Studio可能会针对其他直接构建进行的其他潜在欺骗,我对它们添加此标志并不感到惊讶.就我个人而言,我希望有一个更明确的选择退出所有这些恶作剧(可能还带有此标志),因为我是那些想让我从IDE运行的应用程序与用户运行的应用程序相同的怪人之一.

Given Instant Run and other potential shenanigans that Android Studio might be doing for direct-run builds versus other ones, I am not surprised that they added this flag. Personally, I would love a clearer option to opt out of all such shenanigans (and perhaps this flag), as I'm one of those weirdos who wants the app that I run from the IDE to be the same app that my users run.

FWIW,我在 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆