android apk 执行环境,Xamarin.Android 环境

Xamarin.Android 环境Xamarin.Android Environment

02/15/2018

本文内容

执行环境Execution Environment

执行环境是一系列影响程序执行的环境变量和 Android 系统属性。The execution environment is the set of environment variables and Android system properties that influence program execution. Android 系统属性可通过 adb shell setprop 命令设置,而环境变量可通过设置 debug.mono.env 系统属性进行设置:Android system properties can be set with the adb shell setprop command, while environment variables can be set by setting the debug.mono.env system property:

## Enable GREF logging

adb shell setprop debug.mono.log gref

## Set the MONO_LOG_LEVEL and MONO_LOG_MASK environment variables

## so that additional Mono messages will be written to `adb logcat`.

adb shell setprop debug.mono.env "'MONO_LOG_LEVEL=info|MONO_LOG_MASK=asm'"

Android 系统属性是针对目标设备上的所有进程而设置的。Android system properties are set for all processes on the target device.

从 Xamarin.Android 4.6 开始,可能会在每个应用的基础上设置或重写系统属性和环境变量,方法是将环境文件添加到项目。Starting with Xamarin.Android 4.6, both system properties and environment variables may be set or overridden on a per-app basis by adding an environment file to the project. 环境文件是 Unix 格式的纯文本文件,附带 AndroidEnvironment 的生成操作。An environment file is a Unix-formatted plain-text file with a Build action of AndroidEnvironment.

环境文件包含键=值格式的行。The environment file contains lines with the format key=value.

注释是以 # 开头的行。Comments are lines which start with #. 空行将被忽略。Blank lines are ignored.

如果密钥以大写字母开头,密钥将被视为一个环境变量,且 setenv(3) 用于在进程启动过程中将环境变量设置为指定值。If key starts with an uppercase letter, then key is treated as an environment variable and setenv(3) is used to set the environment variable to the specified value during process startup.

如果密钥以小写字母开头,则密钥会被视为 Android 系统属性,且值为默认值:首先从 Android 系统属性存储查找控制 Xamarin.Android 执行行为的 Android 系统属性,如果未指定任何值,则使用环境文件中指定的值。If key starts with a lowercase letter, then key is treated as an Android system property and value is the default value: Android system properties which control Xamarin.Android execution behavior are looked up first from the Android system property store, and if no value is present then the value specified in the environment file is used. 这是为了允许 adb shell setprop 用于重写来自环境文件的值,以进行诊断。This is to permit adb shell setprop to be used to override values which come from the environment file for diagnostic purposes.

Xamarin.Android 环境变量Xamarin.Android Environment Variables

Xamarin.Android 支持 XA_HTTP_CLIENT_HANDLER_TYPE 变量,可通过 adb shell setprop debug.mono.env 或 $(AndroidEnvironment) 生成操作进行设置。Xamarin.Android supports the XA_HTTP_CLIENT_HANDLER_TYPE variable, which may be set either via adb shell setprop debug.mono.env or via the $(AndroidEnvironment) Build action.

XA_HTTP_CLIENT_HANDLER_TYPE

The assembly-qualified type which must inherit from HttpMessageHandler and is constructed from the HttpClient() default constructor.

在 Xamarin.Android 6.1 中,默认情况下不会设置此环境变量,且会使用 HttpClientHandler。In Xamarin.Android 6.1, this environment variable is not set by default, and HttpClientHandler will be used.

或者,可以指定值 Xamarin.Android.Net.AndroidClientHandler 使用 java.net.URLConnectionAlternatively, the value Xamarin.Android.Net.AndroidClientHandler may be specified to use java.net.URLConnection

进行网络访问,该操作可允许使用 TLS 1.2(在获得 Android 支持的情况下)。for network access, which may permit use of TLS 1.2 when Android supports it.

已在 Xamarin.Android 6.1 中添加。Added in Xamarin.Android 6.1.

Xamarin.Android 系统属性Xamarin.Android System Properties

Xamarin.Android 支持以下系统属性,可通过 adb shell setprop 或 $(AndroidEnvironment) 生成操作进行设置。Xamarin.Android supports the following system properties, which may be set either via adb shell setprop or via the $(AndroidEnvironment) Build action.

debug.mono.debug

debug.mono.env

debug.mono.gc

debug.mono.log

debug.mono.max_grefc

debug.mono.profile

debug.mono.runtime_args

debug.mono.trace

debug.mono.wref

XA_HTTP_CLIENT_HANDLER_TYPE

debug.mono.debug

debug.mono.debug 系统属性的值是一个整数。The value of the debug.mono.debug system property is an integer. 若为 1,则表现为就好像进程是以 mono --debug 开始的。If 1, then behave "as if" the process were started with mono --debug.

这通常会在堆栈跟踪中显示文件和行信息等内容,而无需应用通过调试器启动。This generally shows file and line information in stack traces, etc., without requiring that the app be started from a debugger.

debug.mono.env

包含环境变量以 | 分隔的列表。Contains a |-separated list of environment variables.

debug.mono.gc

debug.mono.gc 系统属性的值是一个整数。The value of the debug.mono.gc system property is an integer.

若为 1,则应记录 GC 信息。If 1, then GC information should be logged.

这相当于使 debug.mono.log 系统属性包含 gc。This is equivalent to having the debug.mono.log system property contain gc.

debug.mono.log

控制 Xamarin.Android 将记录到 adb logcat 的其他信息。Controls which additional information Xamarin.Android will log to adb logcat.

它是一个以逗号分隔的字符串 (,),包含以下值之一:It is a comma-separated string (,), containing one of the following values:

all:打印所有消息。all: Print out all messages. 这不是一个好主意,因为它包含 lref 消息。This is seldom a good idea, as it includes lref messages.

assembly:打印 .apk 和程序集分析消息。assembly: Print out .apk and assembly parsing messages.

gc:打印与 GC 相关的消息。gc: Print out GC-related messages.

gref:打印 JNI 全局引用消息。gref: Print out JNI Global Reference messages.

lref:打印 JNI 本地引用消息。lref: Print out JNI Local Reference messages.

备注

这将是真正的垃圾邮件adb logcat。This will really spam adb logcat.

在 Xamarin.Android 5.1 中,它还会创建 .__override__/lrefs.txt 文件,从中获取 gigantic。In Xamarin.Android 5.1, this will also create a .__override__/lrefs.txt file, which can get gigantic.

请避免。Avoid.

timing:打印某些方法计时信息。timing: Print out some method timing information. 这还将创建文件 .__override__/methods.txt 和 .__override__/counters.txt。This will also create the files .__override__/methods.txt and .__override__/counters.txt.

debug.mono.max_grefc

debug.mono.max_grefc 系统属性的值是一个整数。The value of the debug.mono.max_grefc system property is an integer.

其值会重写默认检测到的目标设备的最大 GREF 计数。It's value overrides the default detected maximum GREF count for the target device.

请注意: 这只能与 adb shell setprop debug.mono.max_grefc 一起使用,因为当此值在 environment.txt 文件中时将不可用 。Please note: This is only usable with adb shell setprop debug.mono.max_grefc as the value will not be available in time with an environment.txt file.

debug.mono.profile

debug.mono.profile 系统属性将启用探查器。The debug.mono.profile system property enables the profiler.

它等效于 mono --profile 选项,并使用与之相同的值。It is equivalent to, and uses the same values as, the mono --profile option. (请参阅 mono(1) 手册页了解详细信息。)(See the mono(1) man page for more information.)

debug.mono.runtime_args

debug.mono.runtime_args 系统属性包含应通过 mono 分析的其他选项。The debug.mono.runtime_args system property contains additional options that should be parsed by mono.

debug.mono.trace

debug.mono.trace 系统属性将启用跟踪。The debug.mono.trace system property enables tracing.

它等效于 mono --trace 选项,并使用与之相同的值。It is equivalent to, and uses the same values as, the mono --trace option. (请参阅 mono(1) 手册页了解详细信息。)(See the mono(1) man page for more information.)

一般情况下,不使用。In general, do not use. 使用跟踪将发送垃圾邮件 adb logcat 输出,严重减慢程序行为,并更改程序行为(直至并包括添加其他错误情况)。Use of tracing will spam adb logcat output, severaly slow down program behavior, and alter program behavior (up to and including adding additional error conditions).

但是有些时候,它允许执行某些进一步研究...Sometimes, however, it allows some additional investigation to be performed...

debug.mono.wref

debug.mono.wref 系统属性可重写默认检测到的 JNI 弱引用机制。The debug.mono.wref system property allows overriding the default detected JNI Weak Reference mechanism. 有两个支持的值:There are two supported values:

jni:使用 JNI 弱引用,由 JNIEnv::NewWeakGlobalRef() 创建并由 JNIEnv::DeleteWeakGlobalREf() 销毁。jni: Use JNI weak references, as created by JNIEnv::NewWeakGlobalRef() and destroyed by JNIEnv::DeleteWeakGlobalREf().

java:使用引用 java.lang.WeakReference 实例的 JNI 全局引用。java: Use JNI Global references which reference java.lang.WeakReference instances.

默认情况下使用 java,通过 API 7 和 API-19 (Kit Katt) 启用,同时启用 ART。java is used, by default, up through API-7 and on API-19 (Kit Kat) with ART enabled. (API 8 添加了 jni 引用,而 ART 中断了 jni 引用。)(API-8 added jni references, and ART broke jni references.)

此系统属性可用于测试和进行某些形式的调查。This system property is useful for testing and certain forms of investigation.

一般情况下,不应更改此属性。In general, it should not be changed.

XA_HTTP_CLIENT_HANDLER_TYPEXA_HTTP_CLIENT_HANDLER_TYPE

在 Xamarin.Android 6.1 中首次引入,此环境变量声明将由 HttpClient 使用的默认 HttpMessageHandler 实现。First introduced in Xamarin.Android 6.1, this environment variable declares the default HttpMessageHandler implementation that will be used by the HttpClient. 默认情况下不设置此变量,Xamarin.Android 将使用 HttpClientHandler。By default this variable is not set, and Xamarin.Android will use the HttpClientHandler.

XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler

备注

基础 Android 设备必须支持 TLS 1.2。The underlying Android device must support TLS 1.2.

Android 5.0 及更高版本支持 TLS 1.2Android 5.0 and later support TLS 1.2

示例Example

## Comments are lines which start with '#'

## Blank lines are ignored.

## Enable GREF messages to `adb logcat`

debug.mono.log=gref

## Clear out a Mono environment variable to decrease logging

MONO_LOG_LEVEL=

相关链接Related Links

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值