新建一个Android项目 28.0.0

作者: wxyass 分类: Android 发布时间: 2019-02-06 09:32

当我们新建一个项目时,会报一些看不懂错误,这多数是引用包错误导致的,那么如何修改使之不报错呢?

1 按照流程先新建一个项目,对于报错先不管

2 修改最外层项目工程build.gradle文件,在低端添加ext代码

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    compileSdkVersion = 28
    // buildToolsVersion = "27.0.0"
    minSdkVersion = 16
    targetSdkVersion = compileSdkVersion

    v4Version = "28.0.0"
}

3 修改内层app的build.gradle文件,调用ext代码

附上代码

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.compileSdkVersion
    // buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        applicationId "com.wxyass.testdemo"
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    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'

    //Android Support包
    api "com.android.support:appcompat-v7:$rootProject.v4Version"
    api "com.android.support:design:$rootProject.v4Version"
    api "com.android.support:cardview-v7:$rootProject.v4Version"
    api "com.android.support:recyclerview-v7:$rootProject.v4Version"
    api "com.android.support:support-v4:$rootProject.v4Version"
    api "com.android.support:support-v13:$rootProject.v4Version"
    api 'com.android.support:multidex:1.0.1'
}

4 重写自动忽略规则.gitignore

https://blog.csdn.net/q9104422999/article/details/52665032


*.iml .gradle /.gradle .gradle/ .idea/ /.idea .idea build/ build /build local.properties /local.properties captures/ /captures #built application files *.apk *.ap_ # Files for the ART/Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ out/ # Windows thumbnail db Thumbs.db # OSX files .DS_Store # Eclipse project files .classpath .project # Android Studio Navigation editor temp files .navigation/ # Signing files .signing/ # Keystore files *.jks # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) google-services.json # Freeline freeline.py freeline/ freeline_project_description.json # fastlane fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output fastlane/readme.md

5 删除自动生成的文件夹,然后编译使其重新生成(置灰表示不上传)

代码下载

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注