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

查看:28
本文介绍了为什么 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(s)"菜单选项也能正常工作.

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.

鉴于 Android Studio 可能会为直接运行构建与其他构建相比,Instant Run 和其他潜在的恶作剧,我对他们添加此标志并不感到惊讶.就我个人而言,我希望有一个更清晰的选项来选择退出所有这些恶作剧(也许还有这个标志),因为我是那些希望我从 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,我在 这篇博文.

这篇关于为什么 Android Studio 3.0.0 在 APK 上设置 FLAG_TEST_ONLY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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