多渠道共存打包(一)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_23195583/article/details/53781764

我的工程源代码请点击这里

看一下项目的目录结构:
项目目录结构
和main同级的并且以z开头的就是可以打的包,名字就是main的包名+其名称:app-z20111308069-debug.apk,就是这样的
如何创建这样的项目结构以及如何打出相应的包,下面来详细说一下。
创建项目初始的时候是一样的,需要把不同的东西抽取到配置文件中,比如说:icon,appname,baseurl
三个包
这是一套代码打的三个包
这里起到主要作用的是清单文件和gradle
gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.fanyafeng.codetopackage"
        minSdkVersion 16
        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'
        }
    }

    productFlavors {
        z20111308011 {
            applicationId "com.fanyafeng.codetopackage.z20111308011"
            manifestPlaceholders = [APP_NAME: "求福"]
        }
        z20111308016 {
            applicationId "com.fanyafeng.codetopackage.z20111308016"
            manifestPlaceholders = [APP_NAME: "红酒"]
        }
        z20111308069 {
            applicationId "com.fanyafeng.codetopackage.z20111308069"
            manifestPlaceholders = [APP_NAME: "测试"]
        }
    }


}

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.1.0'
    compile 'com.android.support:design:25.1.0'
    testCompile 'junit:junit:4.12'
}

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fanyafeng.codetopackage">

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="${APP_NAME}"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".main.MainActivity"
            android:label="${APP_NAME}"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

在这里感觉$这个符号的作用和前端的很像,还有就是这个项目我用的mvp模式,下文再说代码的事,顺便再熟悉一下mvp

猜你喜欢

转载自blog.csdn.net/qq_23195583/article/details/53781764
今日推荐