继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

android studio如何创建一个子module并引入主工程

nickcau
关注TA
已关注
手记 114
粉丝 6510
获赞 303

首先我们new 一个Module:

https://img4.mukewang.com/5c1e417c0001d69617161140.jpg

在弹出框中选择Library:

https://img4.mukewang.com/5c1e41a90001248b18001334.jpg


https://img1.mukewang.com/5c1e41bd00011e4a17801326.jpg

然后press finish:

https://img.mukewang.com/5c1e41d000010fd013321314.jpg

https://img4.mukewang.com/5c1e425a0001069a22461242.jpg

在build.gradle写下面这句话,library就被引用了

compile project(":mylibrary")

有一个地方需要特别注意,这个libary的support-v4包的版本可能跟主版本不一样,那么最好改成跟主版本一样,这样不会有编译问题,很多时候编译问题就在于这些包的版本不一样

这个新建立的libary的build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.0"


    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:23.1.1'
    testCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

}


https://img3.mukewang.com/5c1e41bb00011e4a17801326.jpg


打开App,阅读手记
2人推荐
发表评论
随时随地看视频慕课网APP