美文网首页
怎么将可运行的项目变成一个Lib库

怎么将可运行的项目变成一个Lib库

作者: 我弟是个程序员 | 来源:发表于2017-07-24 17:33 被阅读0次

    在下亲自新建了一个可运行的module,和一个library,通过比较他们的差异,得出的结论。由此,可以实现组件化开发

    module的gridle文件:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 25
        buildToolsVersion "26.0.0"
        defaultConfig {
            applicationId "com.dingfang.org.componentdemo"
            minSdkVersion 15
            targetSdkVersion 25
            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'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:26.+'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        testCompile 'junit:junit:4.12'
    }
    

    library库的gridle文件:

    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 25
        buildToolsVersion "26.0.0"
    
        defaultConfig {
            minSdkVersion 15
            targetSdkVersion 25
            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'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:25.2.0'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        testCompile 'junit:junit:4.12'
    }
    
    

    比较下来,就只有两个区别,module比library的gridle文件这里不同:

    apply plugin: 'com.android.application'
    
    apply plugin: 'com.android.library'
    

    然后多了一个

    applicationId "com.dingfang.org.componentdemo"  //为包名
    

    所以只用将module的 apply plugin: 'com.android.application' 修改成 apply plugin: 'com.android.library',然后去掉applicationId ,并且去掉AndroidManifest.xmlapplication 节点name属性以及以下代码:

                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
    

    以上就完成了module向library的转换。反过来,操作也就不用多说了吧。

    相关文章

      网友评论

          本文标题:怎么将可运行的项目变成一个Lib库

          本文链接:https://www.haomeiwen.com/subject/ypgbkxtx.html