Commit c1bff884 by Denglingling

调整安卓、IOS配置:1、新增插件`rn-fetch-blob`支持下载;2、新增根据配置版本,自动修改两个环境版本号;3、新增两个环境获取版本信息相关功能等

parent 6b897e07
...@@ -18,3 +18,4 @@ ...@@ -18,3 +18,4 @@
- 基于 `react-native-splash-screen` 实现 `APP` 启动页布局 - 基于 `react-native-splash-screen` 实现 `APP` 启动页布局
- 基于 `react-native-camera` 实现扫描条形码功能 - 基于 `react-native-camera` 实现扫描条形码功能
- 基于 `react-native-image-zoom-viewer` 实现图片放大功能 - 基于 `react-native-image-zoom-viewer` 实现图片放大功能
- 基于 `rn-fetch-blob` 实现下载文件
apply plugin: "com.android.application" apply plugin: "com.android.application"
import com.android.build.OutputFile import com.android.build.OutputFile
import groovy.json.JsonSlurper
/** /**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
...@@ -76,7 +77,7 @@ project.ext.react = [ ...@@ -76,7 +77,7 @@ project.ext.react = [
entryFile: "index.js" entryFile: "index.js"
] ]
apply from: "../../node_modules/react-native/react.gradle" //apply from: "../../node_modules/react-native/react.gradle"
/** /**
* Set this to true to create two separate APKs instead of one: * Set this to true to create two separate APKs instead of one:
...@@ -93,8 +94,18 @@ def enableSeparateBuildPerCPUArchitecture = false ...@@ -93,8 +94,18 @@ def enableSeparateBuildPerCPUArchitecture = false
*/ */
def enableProguardInReleaseBuilds = false def enableProguardInReleaseBuilds = false
//获取配置文件的版本信息
def getAppVersion() {
def inputFile = new File("../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}
def appVersion = getAppVersion()
android { android {
compileSdkVersion rootProject.ext.compileSdkVersion compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
...@@ -106,7 +117,7 @@ android { ...@@ -106,7 +117,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1 versionCode 1
versionName "1.1.4" versionName appVersion
missingDimensionStrategy 'react-native-camera', 'general' missingDimensionStrategy 'react-native-camera', 'general'
} }
splits { splits {
...@@ -155,16 +166,27 @@ static def releaseTime() { ...@@ -155,16 +166,27 @@ static def releaseTime() {
} }
dependencies { dependencies {
implementation project(':rn-fetch-blob')
implementation project(':react-native-fs')
implementation project(':react-native-date-picker')
implementation project(':react-native-image-picker')
implementation project(':react-native-camera') implementation project(':react-native-camera')
implementation project(':react-native-splash-screen') implementation project(':react-native-splash-screen')
implementation project(':react-native-date-picker')
implementation project(':react-native-sound') implementation project(':react-native-sound')
implementation project(':react-native-audio') implementation project(':react-native-audio')
implementation project(':react-native-gesture-handler') implementation project(':react-native-gesture-handler')
implementation project(':react-native-image-picker')
implementation fileTree(dir: "libs", include: ["*.jar"]) implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules implementation "com.facebook.react:react-native:+" // From node_modules
// implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation "androidx.multidex:multidex:2.0.0"
// implementation 'androidx.appcompat:appcompat:1.0.2'
// implementation 'androidx.core:core:1.0.1'
// implementation 'androidx.legacy:legacy-support-v4:1.0.0'
// implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// implementation 'androidx.annotation:annotation:1.0.1'
// implementation 'com.google.android.material:material:1.1.0-alpha02'
} }
// Run this once to be able to run the application with BUCK // Run this once to be able to run the application with BUCK
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<application <application
android:name=".MainApplication" android:name=".MainApplication"
...@@ -32,9 +34,19 @@ ...@@ -32,9 +34,19 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /> <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application> </application>
</manifest> </manifest>
This diff could not be displayed because it is too large.
...@@ -3,13 +3,15 @@ package com.bonehouse_business_app; ...@@ -3,13 +3,15 @@ package com.bonehouse_business_app;
import android.app.Application; import android.app.Application;
import com.facebook.react.ReactApplication; import com.facebook.react.ReactApplication;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.rnfs.RNFSPackage;
import com.henninghall.date_picker.DatePickerPackage;
import com.imagepicker.ImagePickerPackage;
import org.reactnative.camera.RNCameraPackage; import org.reactnative.camera.RNCameraPackage;
import org.devio.rn.splashscreen.SplashScreenReactPackage; import org.devio.rn.splashscreen.SplashScreenReactPackage;
import com.henninghall.date_picker.DatePickerPackage;
import com.zmxv.RNSound.RNSoundPackage; import com.zmxv.RNSound.RNSoundPackage;
import com.rnim.rn.audio.ReactNativeAudioPackage; import com.rnim.rn.audio.ReactNativeAudioPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage; import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.imagepicker.ImagePickerPackage;
import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage; import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage; import com.facebook.react.shell.MainReactPackage;
...@@ -31,14 +33,17 @@ public class MainApplication extends Application implements ReactApplication { ...@@ -31,14 +33,17 @@ public class MainApplication extends Application implements ReactApplication {
protected List<ReactPackage> getPackages() { protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList( return Arrays.<ReactPackage>asList(
new MainReactPackage(), new MainReactPackage(),
new RNFetchBlobPackage(),
new RNFSPackage(),
new DatePickerPackage(),
new ImagePickerPackage(),
new RNCameraPackage(), new RNCameraPackage(),
new SplashScreenReactPackage(), new SplashScreenReactPackage(),
new DatePickerPackage(),
new RNSoundPackage(), new RNSoundPackage(),
new ReactNativeAudioPackage(), new ReactNativeAudioPackage(),
new RNGestureHandlerPackage(), new RNGestureHandlerPackage(),
new ImagePickerPackage(), new OpenSettingsPackage(), /* add */
new OpenSettingsPackage() /* add */ new RNToolsPackage() /* add */
); );
} }
......
package com.bonehouse_business_app;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.uimanager.IllegalViewOperationException;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import com.imagepicker.FileProvider;
import java.io.File;
public class RNToolsManager extends ReactContextBaseJavaModule {
public RNToolsManager(ReactApplicationContext reactContext) {
super(reactContext);
}
// 重写getName方法声明Module类名称,在RN调用时用到
@Override
public String getName() {
return "RNToolsManager";
}
// 声明的获取版本号方法,外界调用
@ReactMethod
public void getAppVersion(Callback successCallback) {
try {
PackageInfo info = getPackageInfo();
if (info != null) {
successCallback.invoke(info.versionName);
} else {
successCallback.invoke("");
}
} catch (IllegalViewOperationException e) {
}
}
// 获取 APP 信息
private PackageInfo getPackageInfo() {
PackageManager manager = getReactApplicationContext().getPackageManager();
PackageInfo info = null;
try {
info = manager.getPackageInfo(getReactApplicationContext().getPackageName(), 0);
return info;
} catch (Exception e) {
e.printStackTrace();
} finally {
return info;
}
}
// 声明的下载方法,外界调用
@ReactMethod
public void openInstallActivity(String path) {
try {
File file = new File(path);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri = FileProvider.getUriForFile(getReactApplicationContext(), "com.bonehouse_business_app.provider", file);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getCurrentActivity().startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
// // 声明的设置域名方法,外界调用
// @ReactMethod
// public void getBaseUrl(Promise promise) {
// String STRING_API_ENV = getReactApplicationContext().getResources().getString(R.string.strKey); // 需要在 android/app/build.gradle 添加'productFlavors'
// promise.resolve(STRING_API_ENV);
// }
}
\ No newline at end of file
package com.bonehouse_business_app;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class RNToolsPackage implements ReactPackage {
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<NativeModule> createNativeModules( ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
// 添加一个安卓原生的activity模块
modules.add(new RNToolsManager(reactContext));
return modules;
}
}
\ No newline at end of file
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion compileSdkVersion
buildToolsVersion "$buildToolsVersion"
}
}
}
}
ext { ext {
buildToolsVersion = "28.0.3" buildToolsVersion = "28.0.3"
minSdkVersion = 16 minSdkVersion = 16
compileSdkVersion = 28 compileSdkVersion = 28
targetSdkVersion = 28 targetSdkVersion = 28
supportLibVersion = "28.0.0" supportLibVersion = "25.0.0"
} }
repositories { repositories {
google() google()
jcenter() jcenter()
maven { maven {url 'http://developer.huawei.com/repo/'}
url 'https://maven.google.com/'
name 'Google'
}
} }
dependencies { dependencies {
classpath("com.android.tools.build:gradle:3.4.0") // classpath('com.android.tools.build:gradle')
classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
...@@ -33,7 +41,13 @@ allprojects { ...@@ -33,7 +41,13 @@ allprojects {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android" url "$rootDir/../node_modules/react-native/android"
} }
maven { url "https://jitpack.io" } maven {
maven { url "https://maven.google.com" } // Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
maven { url 'https://www.jitpack.io' }
} }
} }
task clean(type: Delete) {
delete rootProject.buildDir
}
\ No newline at end of file
...@@ -16,5 +16,5 @@ ...@@ -16,5 +16,5 @@
# This option should only be used with decoupled projects. More details, visit # This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
android.enableJetifier=true android.useAndroidX = true
android.useAndroidX=true android.enableJetifier = true
\ No newline at end of file \ No newline at end of file
#Wed Dec 16 18:33:06 CST 2020 #Sat Jan 02 21:01:55 CST 2021
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
......
rootProject.name = 'BoneHouse_Business_APP' rootProject.name = 'BoneHouse_Business_APP'
include ':rn-fetch-blob'
project(':rn-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/rn-fetch-blob/android')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')
include ':react-native-date-picker'
project(':react-native-date-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-date-picker/android')
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':react-native-camera' include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':react-native-splash-screen' include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android') project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':react-native-date-picker'
project(':react-native-date-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-date-picker/android')
include ':react-native-sound' include ':react-native-sound'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android') project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
include ':react-native-audio' include ':react-native-audio'
project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android') project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android')
include ':react-native-gesture-handler' include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android') project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':app' include ':app'
...@@ -32,6 +32,7 @@ export const GetRequest = (BaseUrl, url) => { ...@@ -32,6 +32,7 @@ export const GetRequest = (BaseUrl, url) => {
}, },
timeout: 300000 //5min超时 timeout: 300000 //5min超时
}; };
console.log('BaseUrl + VERSION + url---', BaseUrl + VERSION + url)
return fetch(BaseUrl + VERSION + url, opts) return fetch(BaseUrl + VERSION + url, opts)
.then(response => response.json()) .then(response => response.json())
.then(data => data) .then(data => data)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string> <string>1.2.3</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
//
// RNToolsManager.h
// BoneHouse_Business_APP
//
// Created by Hilary on 2021/1/25.
// Copyright © 2021 Facebook. All rights reserved.
//
#ifndef RNToolsManager_h
#define RNToolsManager_h
#endif /* RNToolsManager_h */
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
@interface RNToolsManager : NSObject <RCTBridgeModule>
@end
//
// RNToolsManager.m
// BoneHouse_Business_APP
//
// Created by Hilary on 2021/1/25.
// Copyright © 2021 Facebook. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "RNToolsManager.h"
@implementation RNToolsManager
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE(RNToolsManager);
// 对外提供调用方法,Callback
RCT_EXPORT_METHOD(getAppVersion:(RCTResponseSenderBlock)callback)
{
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];//获取项目版本号
callback(@[[NSString stringWithFormat:@"%@",version]]);
}
@end
{ {
"name": "BoneHouse_Business_APP", "name": "BoneHouse_Business_APP",
"version": "0.0.1", "version": "1.2.3",
"private": true, "private": true,
"scripts": { "scripts": {
"postinstall": "npx jetify",
"start": "node node_modules/react-native/local-cli/cli.js start", "start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest" "test": "jest"
}, },
"dependencies": { "dependencies": {
"moment": "2.29.1",
"react": "16.8.3", "react": "16.8.3",
"react-native": "0.59.9", "react-native": "0.59.9",
"react-native-audio": "4.3.0", "react-native-audio": "4.3.0",
"react-native-camera": "^2.10.2", "react-native-camera": "3.40.0",
"react-native-date-picker": "2.7.9", "react-native-date-picker": "2.7.9",
"react-native-gesture-handler": "1.3.0", "react-native-fs": "2.14.1",
"react-native-image-picker": "0.27.0", "react-native-image-picker": "0.28.0",
"react-native-image-zoom-viewer": "^3.0.1", "react-native-image-zoom-viewer": "3.0.1",
"react-native-root-toast": "3.1.1", "react-native-root-toast": "3.1.1",
"react-native-scrollable-tab-view": "^0.9.0", "react-native-scrollable-tab-view": "0.9.0",
"react-native-sound": "0.11.0", "react-native-sound": "0.11.0",
"react-native-splash-screen": "^3.2.0", "react-native-splash-screen": "3.2.0",
"react-navigation": "3.11.0", "react-navigation": "3.11.0",
"react-redux": "7.1.0", "react-redux": "7.1.0",
"redux": "4.0.1", "redux": "4.0.1",
"redux-persist": "5.10.0", "redux-persist": "5.10.0",
"redux-thunk": "2.3.0" "redux-thunk": "2.3.0",
"rn-fetch-blob": "0.12.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.4.5", "@babel/core": "^7.4.5",
...@@ -32,6 +35,7 @@ ...@@ -32,6 +35,7 @@
"jest": "^24.8.0", "jest": "^24.8.0",
"jetifier": "^1.6.6", "jetifier": "^1.6.6",
"metro-react-native-babel-preset": "^0.54.1", "metro-react-native-babel-preset": "^0.54.1",
"react-native-gesture-handler": "1.0.5",
"react-test-renderer": "16.8.3" "react-test-renderer": "16.8.3"
}, },
"jest": { "jest": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment