zoukankan      html  css  js  c++  java
  • 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中的代码
     1 apply plugin: 'com.android.application'
     2 
     3 android {
     4     compileSdkVersion 28
     5     defaultConfig {
     6         applicationId "com.test.test"
     7         minSdkVersion 19
     8         targetSdkVersion 28
     9         versionCode 1
    10         versionName "1.0"
    11         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    12 
    13         //以下是为了找到android.os.SystemProperties这个隐藏的类
    14         String SDK_DIR = System.getenv("ANDROID_HOME")
    15         //("TAG", "SDK_DIR = " + SDK_DIR );
    16         if(SDK_DIR == null) {
    17             Properties props = new Properties()
    18             props.load(new FileInputStream(project.rootProject.file("local.properties")))
    19             SDK_DIR = props.get('sdk.dir');
    20 
    21     }
    22     buildTypes {
    23         release {
    24             minifyEnabled false
    25             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    26         }
    27     }
    28 }
    29 
    30 dependencies {
    31     implementation fileTree(dir: 'libs', include: ['*.jar'])
    32     compileOnly 'com.google.android.wearable:wearable:2.4.0'
    33     implementation 'com.google.android.support:wearable:2.4.0'
    34     implementation 'com.google.android.gms:play-services-wearable:16.0.1'
    35     implementation 'com.android.support:percent:28.0.0'
    36     implementation 'com.android.support:support-v4:28.0.0'
    37     implementation 'com.android.support:recyclerview-v7:28.0.0'
    38     implementation 'com.android.support:appcompat-v7:28.0.0'
    39     implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    40     androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
    41     testImplementation 'junit:junit:4.12'
    42     androidTestImplementation 'com.android.support.test:runner:1.0.2'
    43     compileOnly files("${SDK_DIR}/platforms/android-19/data/layoutlib.jar")
    44 
    45 }

    2、然后在android studio中新建一个class文件,再输入到 import android.os.S...  的时候就会关联出SystemProperties,说明该 jar包引入成功

  • 相关阅读:
    背景图片填充问题
    a:hover 等伪类选择器
    jQuery中animate()方法用法实例
    响应式框架Bootstrap
    HTTP入门
    jQuery选择器
    httplib urllib urllib2 pycurl 比较
    校招
    JAVA描述的简单ORM框架
    Roman to Integer
  • 原文地址:https://www.cnblogs.com/aziji/p/10671988.html
Copyright © 2011-2022 走看看