ReactNative进阶(九)build

        // All of Detox' artifacts are provided via the npm module
        url "$rootDir/../node\_modules/detox/Detox-android"
    }
    maven { url "https://jitpack.io" }
    google()
    jcenter()
}

}

def REACT_NATIVE_VERSION = new File([‘node’, ‘–print’,“JSON.parse(require(‘fs’).readFileSync(require.resolve(‘react-native/package.json’), ‘utf-8’)).version”].execute(null, rootDir).text.trim())

allprojects {
configurations.all {
resolutionStrategy {
force “com.facebook.react:react-native:” + REACT_NATIVE_VERSION
}
}
}


* `repositories{}`闭包:配置远程仓库。  
 该闭包中可声明`jcenter()`和`google()`的配置,其中`jcenter`是一个代码托管仓库,上面托管了很多`Android`开源项目,在这里配置了`jcenter`后我们可以在项目中方便引用`jcenter`上的开源项目,从Android Studio3.0后新增了`google()`配置,可以引用`google`上的开源项目。
* `dependencies{}`闭包:配置构建工具。  
 该闭包使用`classpath`声明了一个`Gradle`插件,由于`Gradle`并不只是用来构建`Android`项目,因此此处引入相关插件来构建`Android`项目,其中’3.0.0’为该插件的版本号,可以根据最新的版本号来调整。


### 三、Module 的 build.gradle 文件


从文件内容可以看出,主要分为三大配置节点:`apply plugin`、`android`、`dependencies`。对应的`build.gradle`代码如下:



// 声明是Android程序,
// com.android.application 表示该模块为应用程序模块,可以直接运行,打包得到的是.apk文件
// com.android.library 表示该模块为库模块,只能作为代码库依附于别的应用程序模块来运行,打包得到的是.aar文件
// 两者区别:前者可以直接运行,后着是依附别的应用程序运行
apply plugin: “com.android.application”

import com.android.build.OutputFile

/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call react-native bundle with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* apply from: "../../node\_modules/react-native/react.gradle" line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: “index.android.bundle”,
*
* // the entry file for bundle generation
* entryFile: “index.android.js”,
*
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
* bundleCommand: “ram-bundle”,
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // ‘bundleIn p r o d u c t F l a v o r {productFlavor} productFlavor{buildType}’
* // ‘bundleInKaTeX parse error: Undefined control sequence: \* at position 15: {buildType}' \̲*̲ // bundleInFre…{productFlavor}KaTeX parse error: Undefined control sequence: \* at position 15: {buildType}' \̲*̲ // 'devDisable…{buildType}’
*
* // the root of your project, i.e. where “package.json” lives
* root: “…/…/”,
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: “KaTeX parse error: Undefined control sequence: \* at position 40: …ssets/debug", \̲*̲ \* // where t…buildDir/intermediates/assets/release”,
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require(‘./image.png’)), in debug mode
* resourcesDirDebug: “KaTeX parse error: Undefined control sequence: \* at position 44: …erged/debug", \̲*̲ \* // where t…buildDir/intermediates/res/merged/release”,
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don’t look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: [“android/**”, “ios/**”],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: [“node”],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/

project.ext.react = [
entryFile: “index.js”,
enableHermes: false, // clean and rebuild if changing
bundleAssetName: “index.android.bundle”,
bundleInDebug: true,
bundleInBeta: true,
nodeExecutableAndArgs: [“/usr/local/bin/node”]
]

apply from: “…/…/node_modules/react-native/react.gradle”

/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false

/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false

/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* def jscFlavor = 'org.webkit:android-jsc-intl:+'
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. Date.toLocaleString and String.localeCompare that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = ‘org.webkit:android-jsc:+’

/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get(“enableHermes”, false);

android {
// 指定编译用的SDK版本号。比如30表示Android11.0编译
compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
    // 指定该模块的应用编号,也就是app的包名 应用编号需要和AndroidManifest中package相同
    applicationId "com.shq5785"
    // 指定App适合运行的最小SDK版本号。
    minSdkVersion rootProject.ext.minSdkVersion
    /\*\*

* 指定目标设备的SDK版本号,表示在该目标版本上已经做过充分测试,系统会为该应用启动一些对应该目标系统的最新功能特性,
* Android系统平台的行为变更,只有targetSdkVersion的属性值被设置为大于或等于该系统平台的API版本时,才会生效。
* 例如,若指定targetSdkVersion值为22,则表示该程序最高只在Android5.1版本上做过充分测试,
* 在Android6.0系统上(对应targetSdkVersion为23)拥有的新特性如系统运行时权限等功能就不会被启用。
*/
targetSdkVersion rootProject.ext.targetSdkVersion
// 指定App的应用版本号,一般每次打包上线时该值只能增加,打包后看不见。
versionCode 16872701
// 指定App的应用版本名称,展示在应用市场上。
versionName “2.2.6”
multiDexEnabled true
testBuildType System.getProperty(‘testBuildType’, ‘debug’)
// 表明要使用AndroidJUnitRunner进行单元测试。
testInstrumentationRunner ‘androidx.test.runner.AndroidJUnitRunner’
ndk {
//设置支持的SO库架构
abiFilters “armeabi”, “armeabi-v7a”, “x86_64” //, “arm64-v8a”
}
missingDimensionStrategy ‘react-native-camera’, ‘general’
}
// 配置目录指向
// sourceSets {
// main.jniLibs.srcDirs = [‘libs’]
// }

splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK , "x86\_64" "arm64-v8a",
        include "armeabi-v7a", "x86",  "x86\_64"
    }
}
// 自动化打包配置
signingConfigs {

// debug {
// storeFile file(‘debug.keystore’)
// storePassword ‘android’
// keyAlias ‘androiddebugkey’
// keyPassword ‘android’
// }
// 开发环境
debug {
if (project.hasProperty(‘MYAPP_RELEASE_STORE_FILE’)) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
// 线上环境
release {
if (project.hasProperty(‘MYAPP_RELEASE_STORE_FILE’)) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
// 指定生成安装文件的主要配置
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.debug // 设置签名信息
minifyEnabled enableProguardInReleaseBuilds // 是否对代码进行混淆
// 代码混淆的混淆规则,proguard-android.txt文件为默认的混淆文件,里面定义了一些通用的混淆规则。
// proguard-rules.pro文件位于当前项目的根目录下,可以在该文件中定义一些项目特有的混淆规则。
proguardFiles getDefaultProguardFile(“proguard-android.txt”), “proguard-rules.pro”
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html , “x86_64”: 4
def versionCodes = [“armeabi-v7a”: 1, “x86”: 2, “x86_64”: 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}

    }
}
// 打包时的相关配置
packagingOptions {
    // pickFirsts的作用是当有文件重复时打包会报错,这样配置会使用第一个匹配的文件打包进入apk
    // 表示当apk中有重复的armeabi-v7a目录下有重复的libc++\_shared.so文件时只用第一个,这样打包就不会报错
    pickFirst '\*\*/armeabi-v7a/libc++\_shared.so'
    pickFirst '\*\*/x86/libc++\_shared.so'
    pickFirst '\*\*/x86\_64/libc++\_shared.so'
    pickFirst '\*\*/x86/libjsc.so'
    pickFirst '\*\*/armeabi-v7a/libjsc.so'
}

repositories {
    flatDir {
        dirs 'libs', '../SDK/libs'
    }
}

// 程序在编译的时候会检查lint,有任何错误提示会停止build,我们可以关闭这个开关
lintOptions {
    abortOnError true // 报错时停止打包
    checkReleaseBuilds false  // 打包release版本的时候进行检测
}

}

// 定义项目的依赖关系
dependencies {
// 用api引入的库整个项目都可以使用,用implementation引入的库只有对应的Module能使用,其他Module不能使用
// 本地jar包依赖
implementation project(‘:react-native-device-info’)
// 远程依赖
api ‘com.tencent.tbs:tbssdk:44286’
implementation “com.android.support:design:25.1.1”
// implementation “com.android.support:appcompat-v7:25.1.0”
implementation “me.imid.swipebacklayout.lib:library:1.1.0”
// implementation “com.google.code.gson:gson:2.2.4”

implementation 'com.facebook.react:react-native:0.60.3'
// From node\_modules
if (enableHermes) {
    def hermesPath = "../../node\_modules/hermesvm/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
    implementation jscFlavor
}

// 依赖本地库
// implementation files(‘libs/ThirdSDK-v3.0.8.jar’)
implementation project(‘:cameraview’)
implementation ‘com.tencent.bugly:crashreport:latest.release’
//其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如2.2.0
implementation ‘com.tencent.bugly:nativecrashreport:latest.release’
// 依赖libs目录下的所有相关类型文件
implementation fileTree(include: [‘*.aar’, ‘*.jar’], exclude: [], dir: ‘libs’)

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
androidTestImplementation('com.wix:detox:+') {
    transitive = true
    exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}
testImplementation 'junit:junit:4.13-beta-2'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha03'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha03'
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:rules:1.3.0-alpha03'
implementation 'androidx.annotation:annotation:1.1.0'
// 依赖本地module,application中引用library
implementation project(':SDK')
implementation 'com.github.getActivity:XXPermissions:18.2'

}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into ‘libs’
}

结尾

正式学习前端大概 3 年多了,很早就想整理这个书单了,因为常常会有朋友问,前端该如何学习,学习前端该看哪些书,我就讲讲我学习的道路中看的一些书,虽然整理的书不多,但是每一本都是那种看一本就秒不绝口的感觉。

以下大部分是我看过的,或者说身边的人推荐的书籍,每一本我都有些相关的推荐语,如果你有看到更好的书欢迎推荐呀。

BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into ‘libs’
}

结尾

正式学习前端大概 3 年多了,很早就想整理这个书单了,因为常常会有朋友问,前端该如何学习,学习前端该看哪些书,我就讲讲我学习的道路中看的一些书,虽然整理的书不多,但是每一本都是那种看一本就秒不绝口的感觉。

以下大部分是我看过的,或者说身边的人推荐的书籍,每一本我都有些相关的推荐语,如果你有看到更好的书欢迎推荐呀。

前端学习书籍导图-1

  • 10
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值