AS构建低版本项目 targetSdkVersion 22

本文旨在写测试Demo的时候,绕开6.0之后的动态权限问题,targetSdkVersion版本就是兼容Android的版本,随着AS的升级,创建出来的新项目的targetSdkVersion版本都会比较高,不利于我们平时写测试demo。这个时候就需要对targetSdkVersion做修改,将其改到23以下即可,但是这里我们手动改的时候,会出一堆问题,项目编译不起来。下面就分享一下我的解决方案
第一步:修改app目录下的build.gradle中的compileSdkVersion,targetSdkVersion改为22,并在该文件中把V7包也改成相应的版本下的


image.png
image.png
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    defaultConfig {
        applicationId "yh.com.mytest"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:22+'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

我这里直接改成22,这个文件会有报红,但是不影响编译。然后Rebuild一下之后可以看到项目编译成功了 但是跑不起来,会有报错


image.png

注意看这里,告诉我们找不到roundIcon属性,全局搜索一下(cart + shift + F)发现在mainface里面可以找到


image.png

这行直接删掉再次编译,发现还有问题:
image.png

这里是找不到一些属性,这里我们在res目录下可以看到标有版本的文件


image.png

直接删掉这两个文件夹再次编译,发现编译成功了,再次安装,发现可以成功安装了!这样我们以后在写测试用例的时候,就不需要进行权限的申请或者手动在手机里添加权限了,只需要在mainface里添加一下权限就可以愉快的编写你的功能代码了。

你可能感兴趣的:(AS构建低版本项目 targetSdkVersion 22)