Commit c1bff884 by Denglingling

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

parent 6b897e07
......@@ -18,3 +18,4 @@
- 基于 `react-native-splash-screen` 实现 `APP` 启动页布局
- 基于 `react-native-camera` 实现扫描条形码功能
- 基于 `react-native-image-zoom-viewer` 实现图片放大功能
- 基于 `rn-fetch-blob` 实现下载文件
apply plugin: "com.android.application"
import com.android.build.OutputFile
import groovy.json.JsonSlurper
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
......@@ -76,7 +77,7 @@ project.ext.react = [
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:
......@@ -93,8 +94,18 @@ def enableSeparateBuildPerCPUArchitecture = 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 {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
......@@ -106,7 +117,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.1.4"
versionName appVersion
missingDimensionStrategy 'react-native-camera', 'general'
}
splits {
......@@ -155,16 +166,27 @@ static def releaseTime() {
}
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-splash-screen')
implementation project(':react-native-date-picker')
implementation project(':react-native-sound')
implementation project(':react-native-audio')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-image-picker')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
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
......
......@@ -14,6 +14,8 @@
<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_FINE_LOCATION" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<application
android:name=".MainApplication"
......@@ -32,9 +34,19 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>
<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>
</manifest>
This diff could not be displayed because it is too large.
......@@ -3,13 +3,15 @@ package com.bonehouse_business_app;
import android.app.Application;
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.devio.rn.splashscreen.SplashScreenReactPackage;
import com.henninghall.date_picker.DatePickerPackage;
import com.zmxv.RNSound.RNSoundPackage;
import com.rnim.rn.audio.ReactNativeAudioPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.imagepicker.ImagePickerPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
......@@ -31,14 +33,17 @@ public class MainApplication extends Application implements ReactApplication {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNFetchBlobPackage(),
new RNFSPackage(),
new DatePickerPackage(),
new ImagePickerPackage(),
new RNCameraPackage(),
new SplashScreenReactPackage(),
new DatePickerPackage(),
new RNSoundPackage(),
new ReactNativeAudioPackage(),
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.
buildscript {
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion compileSdkVersion
buildToolsVersion "$buildToolsVersion"
}
}
}
}
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
supportLibVersion = "25.0.0"
}
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven {url 'http://developer.huawei.com/repo/'}
}
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
// in the individual module build.gradle files
......@@ -33,7 +41,13 @@ allprojects {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
maven {
// 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 @@
# 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
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
\ No newline at end of file
android.useAndroidX = true
android.enableJetifier = true
\ 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
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
......
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'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':react-native-splash-screen'
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'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
include ':react-native-audio'
project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android')
include ':react-native-gesture-handler'
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'
......@@ -32,6 +32,7 @@ export const GetRequest = (BaseUrl, url) => {
},
timeout: 300000 //5min超时
};
console.log('BaseUrl + VERSION + url---', BaseUrl + VERSION + url)
return fetch(BaseUrl + VERSION + url, opts)
.then(response => response.json())
.then(data => data)
......
......@@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<string>1.2.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<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",
"version": "0.0.1",
"version": "1.2.3",
"private": true,
"scripts": {
"postinstall": "npx jetify",
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"moment": "2.29.1",
"react": "16.8.3",
"react-native": "0.59.9",
"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-gesture-handler": "1.3.0",
"react-native-image-picker": "0.27.0",
"react-native-image-zoom-viewer": "^3.0.1",
"react-native-fs": "2.14.1",
"react-native-image-picker": "0.28.0",
"react-native-image-zoom-viewer": "3.0.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-splash-screen": "^3.2.0",
"react-native-splash-screen": "3.2.0",
"react-navigation": "3.11.0",
"react-redux": "7.1.0",
"redux": "4.0.1",
"redux-persist": "5.10.0",
"redux-thunk": "2.3.0"
"redux-thunk": "2.3.0",
"rn-fetch-blob": "0.12.0"
},
"devDependencies": {
"@babel/core": "^7.4.5",
......@@ -32,6 +35,7 @@
"jest": "^24.8.0",
"jetifier": "^1.6.6",
"metro-react-native-babel-preset": "^0.54.1",
"react-native-gesture-handler": "1.0.5",
"react-test-renderer": "16.8.3"
},
"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