index.android.js打包,Reactive Native打包流程

本文详细介绍了在Mac系统中使用React Native打包构建Android APK的步骤,包括生成签名文件、配置签名、修改Gradle配置、启用Proguard以减小APK大小,以及发布前的测试和最终的APK生成位置。确保遵循步骤,妥善保管签名文件,并在发布前充分测试应用。

Mac 下 ReactNative如何打包构建Android apk 的应用。该文章还差一个 打包发布到各个平台的教程

总结

打包 bundle代码

生成签名

添加签名到app中

打包成apk(打包前也可以先运行安装在手机上测试)

把JS代码,打包成 index.android.jsbundle

react-native bundle --entry-file index.android.js --bundle-output ./android/app/src/main/assets/index.android.bundle --platform android --assets-dest ./android/app/src/main/res/ --dev false

打包APK

一、操作步骤:

1. 生成签名

生成一个有效期10000天的证书,证书为: my-release-key.keystore

keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

不要把证书提交到版本控制系统

Note: Remember to keep your keystore file private and never commit it to version control.

2. 配置打包时的签名

把 证书复制到 android/app 目录下

Edit the file ~/.gradle/gradle.properties and add the following (replace ***** with the correct keystore password, alias and key password)

在 gradle.properties 里面添加以下配置

gradle.properties 文件是在 android的根目录下。 官网上的文件位置是错误的。(或者说,我理解错误)

MYAPP_RELEASE_STORE_FILE=my-release-key.keystore

MYAPP_RELEASE_KEY_ALIAS=my-key-alias

MYAPP_RELEASE_STORE_PASSWORD=*****

MYAPP_RELEASE_KEY_PASSWORD=*****

These are going to be global gradle variables, which we can later use in our gradle config to sign our app.

3. 添加签名

Adding signing config to your app's gradle config Edit the file android/app/build.gradle in your project folder and add the signing config,

修改 android/app/build.gradle 添加签名

...

android{

...

defaultConfig{ ... }

signingConfigs{

release{

storeFile file(MYAPP_RELEASE_STORE_FILE)

storePassword MYAPP_RELEASE_STORE_PASSWORD

keyAlias MYAPP_RELEASE_KEY_ALIAS

keyPassword MYAPP_RELEASE_KEY_PASSWORD

}

}

buildTypes{

release{

...

signingConfig signingConfigs.release

}

}

}

...

4. 减小打包apk的大小

Enabling Proguard to reduce the size of the APK (optional) Proguard is a tool that can slightly reduce the size of the APK. It does this by stripping parts of the React Native Java bytecode (and its dependencies) that your app is not using.

IMPORTANT: Make sure to thoroughly test your app if you've enabled Proguard. Proguard often requires configuration specific to each native library you're using. See app/proguard-rules.pro.

修改文件:android/app/build.gradle

To enable Proguard, edit android/app/build.gradle:

/** * Run Proguard to shrink the Java bytecode in release builds. */

def enableProguardInReleaseBuilds= true

5. 发布前测试应用是否有问题

react-native run-android --variant=release

5. 生成apk

生成的apk文件在, android/app/build/outputs/apk/ 下

cd android && ./gradlew assembleRelease

6. apk文件位置

android/app/build/outputs/apk

7. 安装apk文件

adb install app-release.apk

app-release 是发布版的apk文件。

### 介绍 `org.springframework.web.reactive.DispatcherHandler` 是 Spring WebFlux 框架的核心组件之一。Spring WebFlux 是 Spring Framework 5.0 中引入的新的反应式 Web 框架,不需要 Servlet API,完全异步和非阻塞,并通过 Reactor 项目实现 Reactive Streams 规范,可在诸如 Netty、Undertow 和 Servlet 3.1+ 容器的服务器上运行[^3]。`DispatcherHandler` 类似于 Spring MVC 中的 `DispatcherServlet`,负责接收客户端的请求,然后将请求分发给相应的处理器(如控制器方法)进行处理,并将处理结果返回给客户端。 ### 使用方法 以下是一个简单的 Spring WebFlux 项目中使用 `DispatcherHandler` 的示例: 1. **添加依赖** 在 `pom.xml` 中添加 Spring WebFlux 依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> ``` 2. **创建控制器** ```java package com.example.demo.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class IndexController { @GetMapping("/index") public String index() { return "index"; } } ``` 3. **启动 Spring Boot 应用** ```java package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } ``` 在这个示例中,当客户端访问 `/index` 路径时,`DispatcherHandler` 会将请求分发给 `IndexController` 中的 `index` 方法进行处理。 ### 原理 `DispatcherHandler` 的工作原理主要包括以下几个步骤: 1. **接收请求**:`DispatcherHandler` 作为 Spring WebFlux 应用的前端控制器,负责接收所有客户端的请求。 2. **查找处理器**:根据请求的 URL、HTTP 方法等信息,`DispatcherHandler` 会从处理器映射器(`HandlerMapping`)中查找能够处理该请求的处理器(如控制器方法)。 3. **调用处理器**:找到合适的处理器后,`DispatcherHandler` 会调用该处理器来处理请求,并得到处理结果。 4. **处理结果**:`DispatcherHandler` 会将处理器的处理结果返回给客户端。 以下是 `DispatcherHandler` 核心处理逻辑的简化代码示例: ```java import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebHandler; import reactor.core.publisher.Mono; public class DispatcherHandler implements WebHandler { @Override public Mono<Void> handle(ServerWebExchange exchange) { // 查找处理器 // ... // 调用处理器 // ... // 返回结果 return Mono.empty(); } } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值