正文
Android Studio中无法找到android.os.SystemProperties解决办法
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
这个SystemProperties类主要是在这个jar包中layoutlib.jar,所以现在的办法就是让这个 jar包加载到 android studio中
下面讲解如何添加:
1、找到对应项目的 build.gradle文件中,在 dependencies 中添加依赖,添加如下:
compileOnly files("D://Android/Sdk/platforms/android-19/data/layoutlib.jar")注:如果按照网上说的使用provided时会提示这个方法已经过期,用compileOnly代替,由于我的项目是在android4.4上面,对应的API为19,所以就引用了android-19下面的layoutlib.jar文件。
上面文件路径我用的是绝对路径,为使项目在其它电脑上也可以正常使用,建议不要这么使用绝对路径,可以通过获取系统的环境变量,从而知道android sdk在哪个路径下,然后把layout.lib文件组合起来。操作方法如下,直接贴上 build.gradle中的代码
apply plugin: 'com.android.application' android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.test"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" //以下是为了找到android.os.SystemProperties这个隐藏的类
String SDK_DIR = System.getenv("ANDROID_HOME")
//("TAG", "SDK_DIR = " + SDK_DIR );
if(SDK_DIR == null) {
Properties props = new Properties()
props.load(new FileInputStream(project.rootProject.file("local.properties")))
SDK_DIR = props.get('sdk.dir'); }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
} dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly 'com.google.android.wearable:wearable:2.4.0'
implementation 'com.google.android.support:wearable:2.4.0'
implementation 'com.google.android.gms:play-services-wearable:16.0.1'
implementation 'com.android.support:percent:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
compileOnly files("${SDK_DIR}/platforms/android-19/data/layoutlib.jar") }
2、然后在android studio中新建一个class文件,再输入到 import android.os.S... 的时候就会关联出SystemProperties,说明该 jar包引入成功