关于android.os.SystemProperties的使用

本文介绍了如何在Android项目中正确导入第三方库layoutlib.jar,并解决了在编译过程中出现的Java堆内存溢出错误。提供了修改eclipse.ini文件的具体步骤及使用用户库的方法。

android.os.SystemProperties在SDK的库中是没有的,需要把Android SDK 目录下data下的layoutlib.jar文件加到当前工程的附加库路径中,然后在源程序中就可以Import了。

但是这样做会出现一个问题,编译的时候会报错:Unable to execute dex: Java heap space 。在网上找了一下,这个链接比较有帮助:http://programfeelings.blogspot.com/2011/03/unable-to-execute-dex-java-heap-space.html

上面这个链接需要翻墙才能访问,我把内容复制在下面:


最近要用到第三方的庫android-sdk-windows\platforms\android-8\data\layoutlib.jar,但出現Conversion to Dalvik format failed: Unable to execute dex: null這個問題。且出現對話方塊

As Android developer, I have met a strange problem when I want use a third party jar, it remained me that:
Dex Loader] Unable to execute dex: null
Conversion to Dalvik format failed: Unable to execute dex: null
out of memory error…An internal error occurred during: “Build Project”.
Java heap space

This is the DEX Error,I find the solutions by Google, one way is to modify the eclipse.ini, you can increase the memory allocated in eclipse.ini to this: -Xms128m -Xmx512m or something higher, but this didn’t work for me. After modify the eclipse.ini, I cannot start the eclipse. By StackOverflow, I find a solution:

eclipse.ini file must have -vm on first line and path on second line. don’t try to put everything into one line!
-vm
C:\Program Files\Java\jdk1.6.0_07\bin\javaw.exe

After add the -vm and the path in my eclipse.ini, I can start my Eclipse and the problem has been resolved.

Another way to solve the ” Conversion to Dalvik format failed: Unable to execute dex: null” problem is using the user library, the concrete steps are as follows:
1. Right-click the project in Eclipse and select “Build Path -> Add Libraries…”.
2. Select User Library from the list and click Next.
3. Click the “User Libraries…” button.
4. Click “New…” in the User Libraries dialog.
5. Give the user library a name and select the System library checkbox and click OK.
6. Highlight the newly added user library in the list and click the “Add JARs…” button and add the desired jar files.
7. Click OK on the User Libraries dialog.
8. Make sure the new user library is checked in the Add Library dialog and …

<think>嗯,用户想了解android.os.SystemProperties.getBoolean的使用方法和示例。首先,我需要回忆一下这个方法的参数和返回值。记得这个方法有两个参数,第一个是键(key),第二个是默认值(def)。当系统属性不存在或无法解析时,会返回这个默认值。 接下来,我需要确认权限问题。因为系统属性通常受保护,普通应用可能没有权限读取或写入某些属性。特别是像ro.debuggable这样的属性,可能需要系统签名或系统权限才能访问。这一点在引用[1]和[3]中都有提到,所以必须提醒用户注意权限限制。 然后,用户可能需要一个实际的示例代码。我应该提供一个简单的Java示例,展示如何调用getBoolean方法。例如,检查系统是否处于调试模式,使用默认值false。同时,要指出需要导入android.os.SystemProperties类,但根据引用[2],有些情况下这个类可能不可见,特别是在非系统应用中。这时候可能需要反射或者其他方法,但用户的问题主要是关于直接使用,所以先给出标准用法,再提到可能的兼容性问题。 另外,常见问题部分需要涵盖类找不到的情况,权限不足的解决方法,以及如何处理默认值。比如,如果遇到类缺失,可以考虑反射或系统级SDK;权限问题可能需要系统签名或提升应用权限。这些信息在引用[2]和[3]中都有涉及,需要整合到回答中。 还要注意用户可能是在开发系统应用或需要特定系统权限的应用,所以示例和解决方案需要针对这些场景。比如,系统应用可以直接使用,而普通应用可能需要其他变通方法。同时,确保示例代码语法正确,避免错误。 最后,生成相关问题时要围绕SystemProperties的其他方法、权限问题、替代方案等,帮助用户扩展了解相关内容。确保引用标记正确,比如权限问题引用[1][3],类找不到引用[2]。</think>### android.os.SystemProperties.getBoolean 方法解析 #### 1. 方法定义 `SystemProperties.getBoolean` 用于读取Android系统属性中的布尔值,语法为: $$boolean\ getBoolean(String\ key,\ boolean\ def)$$ - **参数说明**: - `key`:系统属性名称(如`persist.sys.debug`) - `def`:当属性不存在或无法解析时的默认返回值 #### 2. 使用条件 - **系统级权限**:需`android.uid.system`权限或系统签名[^1][^3] - **可见性限制**:部分属性仅对系统进程可见(如`ro.`开头的属性) #### 3. 示例代码 ```java // 检查系统调试模式状态 boolean isDebuggable = SystemProperties.getBoolean("ro.debuggable", false); Log.d("SystemProp", "Debug mode: " + isDebuggable); ``` #### 4. 常见问题解决 | 问题场景 | 解决方案 | |---------|----------| | 类找不到错误 | 添加`frameworks-base-core.jar`依赖[^2] | | 权限不足 | 配置`AndroidManifest.xml`添加系统权限[^3] | | 返回值异常 | 检查属性命名规范及作用域限制 | #### 5. 兼容性建议 对于非系统应用,建议改用`Settings.Global`或反射机制获取属性值
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值