ReactNative进阶(九)build

buildscript {
ext {
buildToolsVersion = “28.0.3”
minSdkVersion = 19
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = “28.0.0”
kotlinVersion = ‘1.3.61’
}
repositories {
google()
jcenter()
}
dependencies {
classpath(‘com.android.tools.build:gradle:3.4.1’)

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}

}

// 项目本身需要的依赖,比如项目所需的maven库
allprojects {
repositories {
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url(“KaTeX parse error: Expected 'EOF', got '}' at position 57: …roid") }̲ maven …rootDir/…/node_modules/jsc-android/dist”)
}
maven {
// 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 ->

最后前端到底应该怎么学才好?

如果你打算靠自己摸索自学,那么你首先要了解学习前端的基本大纲,这是你将要学习的主要内容,理解以及掌握好这些内容,便可以找到一份初级的前端开发工作。你还需要有一套完整的前端学习教程,作为初学者最好的方式就是看视频教程学习,初学者容易理解接受。

不要选择买书学习,这样的方式没有几个人能学会,基本都是看不下去书,也看不懂书。如果喜欢看书的学弟,可以买一些经典的书籍作为辅助即可,主要还是以看教程为主。每天抽出固定几个小时学习,做好长期学习的准备。学习编程并不是每天光看视频,你学习编程最重要的目的是为了编写软件产品,提供给大众使用,所以用手写出代码实现功能才是我们要做的事情。

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值