ReactNative进阶(九)build,开发岗面试自我介绍

64 阅读7分钟

JavaScript

  • js的基本类型有哪些?引用类型有哪些?null和undefined的区别。

  • 如何判断一个变量是Array类型?如何判断一个变量是Number类型?(都不止一种)

  • Object是引用类型嘛?引用类型和基本类型有什么区别?哪个是存在堆哪一个是存在栈上面的?

  • JS常见的dom操作api

  • 解释一下事件冒泡和事件捕获

  • 事件委托(手写例子),事件冒泡和捕获,如何阻止冒泡?如何组织默认事件?

  • 对闭包的理解?什么时候构成闭包?闭包的实现方法?闭包的优缺点?

  • this有哪些使用场景?跟C,Java中的this有什么区别?如何改变this的值?

  • call,apply,bind

  • 显示原型和隐式原型,手绘原型链,原型链是什么?为什么要有原型链

  • 创建对象的多种方式

  • 实现继承的多种方式和优缺点

  • new 一个对象具体做了什么

  • 手写Ajax,XMLHttpRequest

  • 变量提升

  • 举例说明一个匿名函数的典型用例

  • 指出JS的宿主对象和原生对象的区别,为什么扩展JS内置对象不是好的做法?有哪些内置对象和内置函数?

  • attribute和property的区别

  • document load和document DOMContentLoaded两个事件的区别

  • JS代码调试

开源分享:docs.qq.com/doc/DSmRnRG… 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", * * // facebook.github.io/react-nativ… * 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 tools.android.com/tech-docs/n… * // The configuration property can be in the following formats * // 'bundleInproductFlavor{productFlavor}{buildType}' * // 'bundleInbuildType\*//bundleInFreeDebug:true,\*//bundleInPaidRelease:true,\*//bundleInBeta:true,\*\*//whethertodisabledevmodeincustombuildvariants(bydefaultonlydisabledinrelease)\*//forexample:todisabledevmodeinthestagingbuildtype(ifconfigured)\*devDisabledInStaging:true,\*//Theconfigurationpropertycanbeinthefollowingformats\*//devDisabledIn{buildType}' \* // bundleInFreeDebug: true, \* // bundleInPaidRelease: true, \* // bundleInBeta: true, \* \* // whether to disable dev mode in custom build variants (by default only disabled in release) \* // for example: to disable dev mode in the staging build type (if configured) \* devDisabledInStaging: true, \* // The configuration property can be in the following formats \* // 'devDisabledIn{productFlavor}buildType\*//devDisabledIn{buildType}' \* // 'devDisabledIn{buildType}' * * // the root of your project, i.e. where "package.json" lives * root: "../../", * * // where to put the JS bundle asset in debug mode * jsBundleDirDebug: "buildDir/intermediates/assets/debug",\*\*//wheretoputtheJSbundleassetinreleasemode\*jsBundleDirRelease:"buildDir/intermediates/assets/debug", \* \* // where to put the JS bundle asset in release mode \* jsBundleDirRelease: "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: "buildDir/intermediates/res/merged/debug",\*\*//wheretoputdrawableresources/ReactNativeassets,e.g.theonesyouusevia\*//require(./image.png)),inreleasemode\*resourcesDirRelease:"buildDir/intermediates/res/merged/debug", \* \* // where to put drawable resources / React Native assets, e.g. the ones you use via \* // require('./image.png')), in release mode \* resourcesDirRelease: "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 facebook.github.io/react-nativ…. 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: // developer.android.com/studio/buil… , "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' }

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

最后

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