使用
git clone
npm install
react-native run-android
react-native run-ios
集成步骤
关于中国移动统一认证: http://dev.10086.cn/wiki/?p5_01_01
1. 集成安卓SDK
(tongyirenzheng sdk_outer_v1.4.0 for Android_0818160907092935)
1.1 转换Eclipse工程
参考:Import and Convert an Eclipse Project into Android Studio
转换后有2个错误,手动解决。
BUILD SUCCESSFUL
Total time: 10.56 secs
在手机上运行测试:(注意高级权限才能获取用户手机号)
1.2 将Android工程转换成Android library project供其他工程引用
参考:Convert existing project to library project in Android Studio
applicationId "cn.richinfo.umcsdk.show"
/Users/duanglink/AndroidStudioProjects/umcsdk-open-demo-androidstudio/app/build.gradle
Warning:(9, 26) Not targeting the latest versions of Android; compatibility modes apply. Consider testing and updating this version. Consult the android.os.Build.VERSION_CODES javadoc for details.
Warning:(10, 5) Not all execution paths return a value
Warning:(18, 1) Not all execution paths return a value
Warning:(21, 13) A newer version of com.android.support:support-v4 than 18.0.0 is available: 24.2.0
解决:error: constant expression required case R.id.umcsdk_test:
参考:what causes "constant expression required" errors for the generated R
/Users/duanglink/AndroidStudioProjects/umcsdk-open-demo-androidstudio/app/src/main/java/cn/richinfo/umcsdk/activity/MainActivity.java
Warning:(93, 7) 'else' statement has empty body
Warning:(128, 9) Condition 'jObj != null' is always 'true'
Warning:(159, 5) 'else' statement has empty body
Library project resource identifiers are not constant static final int
s, just static int s.
Convert the code that needs to switch on library resource ids to if
-else structures.
Further reading: http://tools.android.com/tips/non-constant-fields
测试:
参考:actionbarsherlock - How do I add a library project to Android Studio
11:31:36 AM Please change caller according to com.intellij.openapi.project.IndexNotReadyException documentation: Please change caller according to com.intellij.openapi.project.IndexNotReadyException documentation
/Users/duanglink/AndroidStudioProjects/TestCases/app/src/main/AndroidManifest.xml:7:9-43 Error:
Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest.xml:7:9-43
is also present at [TestCases:umc:unspecified] AndroidManifest.xml:21:9-45 value=(@drawable/ic_launcher).
Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:5:5-18:19 to override.
/Users/duanglink/AndroidStudioProjects/TestCases/app/src/main/AndroidManifest.xml:10:9-40 Error:
Attribute application@theme value=(@style/AppTheme) from AndroidManifest.xml:10:9-40
is also present at [TestCases:umc:unspecified] AndroidManifest.xml:23:9-68 value=(@android:style/Theme.Holo.Light.NoActionBar).
Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:5:5-18:19 to override.
在 /app/src/main/AndroidManifest.xml 添加:tools:replace="android:icon,android:theme"
-
File from non-active changelist if modified
There was a open bug in IDEA regarding this issue:
IDEA-51396 Tasks: if conflicted file is opened in 2 editor tabs, tasks toolbar actions (switch changelist/move changes/ignore) don't make toolbar disappear
It's the IDE behaviours and you don't have to worry about it at all.
Choose what options suits you the best and continue your work.
直接这样调用会报错:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.duanglink.testcases, PID: 28612
java.lang.NoSuchFieldError: No static field sms_login of type I in class Lcn/richinfo/umcsdk/show/R$id; or its superclasses (declaration of 'cn.richinfo.umcsdk.show.R$id' appears in /data/data/com.example.duanglink.testcases/files/instant-run/dex/slice-slice_1-classes.dex)
at cn.richinfo.umcsdk.activity.UMCMainActivity.init(UMCMainActivity.java:70)
at cn.richinfo.umcsdk.activity.UMCMainActivity.onCreate(UMCMainActivity.java:65)
at android.app.Activity.performCreate(Activity.java:5939)
参考:NoSuchFieldError: No static field listView1 of type I in class
The library and the child project has the same layout name : activity_main. Rename either of them solves the problem.
备份:umc.zip
1.3 React Native调原生模块
参考:Native Modules – React Native | A framework for building native apps
注意重载:
java.lang.IllegalStateException: Native module ToastModule tried to override ToastModule for module name ToastAndroid. If this was your intention, return true from ToastModule#canOverrideExistingModule()
声明一个NativeModule类时,需要重写canOverrideExistingModule()及getName()两个方法,在getName中返回的字符串即为在JS中引用的类,即在JS中使用PushHelper来引用PushHelperModule这个类。
文/KenChoi(简书作者)
原文链接:http://www.jianshu.com/p/1925d84d0f5c
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
1.4 React Native调统一认证SDK
完美支持~
升级有风险,需谨慎:
DuangLink-MacBook-Pro:react-native-umc-demo duanglink$ react-native run-android
Starting JS server...
Running /usr/local/opt/android-sdk/platform-tools/adb -s 155556db reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd android && ./gradlew installDebug...
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
FAILURE: Build failed with an exception.
- Where:
Build file '/Users/duanglink/ReactNativeProjects/react-native-umc-demo/android/app/build.gradle' line: 1
- What went wrong:
A problem occurred evaluating project ':app'.
java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
暂时不升级。
2. 集成iOS SDK
(tongyirenzheng sdk_outer_v1.4.0 for iOS_0810160907093159)
2.1 React Native 调用iOS原生模块
参考:统一认证-对外开放开发指南_iOS_v1.4.0-0817(公开版).docx
2016-10-09 10:39:26.068 reactnative_init[276:54000] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
支持: