gpt4 book ai didi

android - 为什么 Android Studio 3.0.0 在 APK 上设置 FLAG_TEST_ONLY?

转载 作者:太空宇宙 更新时间:2023-11-03 12:14:23 24 4
gpt4 key购买 nike

我已经通过 3.0.0-rcX(来自 Canary channel )到达 Android Studio 3.0.0(来自稳定 channel )。

当我启动并构建一个全新的应用程序时,以下代码(应用程序内部)显示已设置 FLAG_TEST_ONLY 标志。

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

应用的 list 是:

<?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>

该标志阻止设备策略 Controller 安装它:Upgrading app in background using Device Policy Controller

为什么要设置这个标志,如何阻止它被设置?

最佳答案

前几天我遇到了这个问题。根据我的测试,仅当您从 Android Studio 运行应用程序时才会添加此标志。不幸的是,APK 文件名并未提示问题所在。而且,尽管有文档,但此 APK可从 Android Studio 中使用 — 我特别尝试通过 adb 安装它,这应该可以工作,但没有。

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

考虑到 Instant Run 和 Android Studio 可能针对直接运行构建与其他构建所做的其他潜在恶作剧,我对他们添加此标志并不感到惊讶。就个人而言,我希望有一个更清晰的选项来选择退出所有此类恶作剧(也许还有这个标志),因为我是那些希望我从 IDE 运行的应用程序与我的用户运行的应用程序相同的怪人之一。

FWIW,我在 this blog post 上有更多这方面的背景资料.

关于android - 为什么 Android Studio 3.0.0 在 APK 上设置 FLAG_TEST_ONLY?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47032507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com