Feeds:
文章
迴響

Archive for 2017 年 07 月

依據 0.46 文件所進行的練習

1. 新增 ImagePickerModule 模組

檔案異動

  • \android\app\src\main\java\com\tools\
    • [Add] ImagePickerModule.java
    • [Modify] AnExampleReactPackage.java
  • \components\
    • [Add] ImagePickerModule.js
  • \
    • [Modify] index.android.js

 

ImagePickerModule.java

AnExampleReactPackage.java

ImagePickerModule.js

index.android.js

執行效果

 

 

 

Read Full Post »

依據 0.46 官方手冊走一遍

1. 新增 React Native Module 的 Java

新增檔案

/android/app/src/main/java/com/tools

  • AnExampleReactPackage.java
  • ToastModule.java

ToastModule.java

AnExampleReactPackage.java

2. Android 引入自訂 React Native Module

修改 android/app/src/main/java/com/rn001/MainApplication.java

3. 建立 React Native Js Module 簡易封裝

新增 /components/ToastAndroid.js

4. 測試 ToastAndroid

修改 index.android.js

打包 apk, gradlew assembleDebug

安裝 apk

啟動 packager

啟動 app

 

Read Full Post »

逍遙安卓好用就不多說了, 如果要用來開發React Native for Android 照標準流程會遇到蠻多坑,我自己的流程是分成幾個步驟

1. 產生 Debug Apk

SET ANDROID_HOME=D:\sdk\android\android-sdk-windows

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

gradlew assembleDebug

2. 逍遙手動安裝 apk

android\app\build\outpus\app-debug.apk

3. 啟動 Packager

set REACT_NATIVE_PACKAGER_HOSTNAME=192.168.1.106

npm start

4. 啟動 App 開發配置

5. 開發程式

一切順利就可以在電腦動態調整 js 直接在逍遙安卓就可以看到結果了…

補充

1. 如果資源檔有更新, 可能需要重新啟動 packager

2. 如果 Hot Reload 沒有生效, 試試手動 Reload

3. JS Remote Debug 需要再 PATH 上可以找到 chrome.exe, 用來查看 console.log 挺方便

Read Full Post »

開發環境

1. Windows 10

2. Android SDK

3. node 8.2.1

4. yarn 0.27.5

建立 Android App

md react-native
cd react-native
yarn init -y
yarn add react-native-cli
react-native init rn001
cd rn001
cd android\app
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
調整 android/app/build.gradle 的簽章配置
cd ..
SET ANDROID_HOME=D:\sdk\android\android-sdk-windows
gradlew assembleRelease

補充1:  build.gradle 調整

(1) 依據 keytool 配置調整

補充2: Android SDK 版本

(2) Android 的 API 和 Build 版本要吻合, 否則會出錯, 預設產生的是 23, 可啟動 %ANDROID_HOME%\tools\android.bat 啟動 SDK Manager 確認

補充3 package.json

測試 apk

  • /android/app/build/outputs/apk/app-release.apk

目錄結構

/android
│  build.gradle
│  gradle.properties
│  gradlew
│  gradlew.bat
│  settings.gradle
│  
├─app
│  │  BUCK
│  │  build.gradle
│  │  proguard-rules.pro
│  │  
│ ├─build
│ │ ├─outputs
│ │ │ │ 
│ │ │ ├─apk
│ │ │ │ app-release.apk
│  └─src
│      └─main
│          │  AndroidManifest.xml   ; Android 配置檔
│          │  
│          ├─java
│          │  └─com
│          │      └─rn001
│          │              MainActivity.java
│          │              MainApplication.java
│          │              
│          └─res
│              ├─mipmap-hdpi
│              │      ic_launcher.png
│              │      
│              ├─mipmap-mdpi
│              │      ic_launcher.png
│              │      
│              ├─mipmap-xhdpi
│              │      ic_launcher.png
│              │      
│              ├─mipmap-xxhdpi
│              │      ic_launcher.png
│              │      
│              └─values
│                      strings.xml
│                      styles.xml
│                      
├─gradle
│  └─wrapper
│          gradle-wrapper.jar
│          gradle-wrapper.properties
│          
└─keystores
        BUCK
        debug.keystore.properties
/ios
├─rn001
│  │  AppDelegate.h
│  │  AppDelegate.m
│  │  Info.plist
│  │  main.m
│  │  
│  ├─Base.lproj
│  │      LaunchScreen.xib
│  │      
│  └─Images.xcassets
│      └─AppIcon.appiconset
│              Contents.json
│              
├─rn001-tvOS
│      Info.plist
│      
├─rn001-tvOSTests
│      Info.plist
│      
├─rn001.xcodeproj
│  │  project.pbxproj
│  │  
│  └─xcshareddata
│      └─xcschemes
│              rn001-tvOS.xcscheme
│              rn001.xcscheme
│              
└─rn001Tests
        Info.plist
        rn001Tests.m
/node_modules
/__tests__
.babelrc
.buckconfig
.flowconfig
.watchmanconfig
app.json
index.android.js
index.ios.js
package.json

 

Read Full Post »

環境

  1. Windows 10
  2. TDM-GCC x64 5.1.0
  3. CMake 3.8
  4. Python 2.7.7

注意

  1. sh.exe 不能在 PATH 環境變數中被找到, 如果安裝 Git 記得編譯前將路徑從 PATH 中移除
  2. gcc, cmake, python 所在路徑加到 PATH 環境變數

編譯

git clone https://github.com/BYVoid/OpenCC.git
cd OpenCC
cmake -H. -Bbuild -G "MinGW Makefiles" 
cmake --build build --config Release 

編譯結果

/build/src
    * libopencc.dll
    * libopencc.dll.a
    * Opencc_Export.h
    * /tools
        * libopencc.dll
        * opencc.exe
        * opencc_dict.exe
        * opencc_phrase_extract.exe
/data/config/*.json -- 配置檔

Read Full Post »

測著測著就來到 1.0 正式版.. 這算是目前測過比較完整的官方範例, 包含後端的網路建立(Peer*3, Orderer*1, CA*2), ChainCode *1, 前端的 Fabric-sdk-node 呼叫測試

快速建立後端網路

  1. 下載 https://github.com/hyperledger/fabric-samples/tree/master/balance-transfer
  2. 調整 artifacts/docker-compose.yaml 的 volumes 對應
  3. docker-compose -f docker-compose.yaml up -d

網路初始的容器狀態

建立 fabric-sdk-node 容器

  1. docker pull node:6.9.0
    • 官方說法目前不支援 7.x, 8.x
  2. 修改 balance-transfer/config.json 和 balance-transfer/app/network-config.json 的 localhost 成 docker mahcine ip
    • docker machine ip 可用 docker-machine ip 取得
  3. docker run -it –name fsn -v /host/balance-transfer:/code node:6.9.0 bash
  4. mkdir -p /tmp/app
  5. cp -r /code/. /tmp/app
    • 因為直接在 volume 映射目錄初始化會出現建立 soft link 失敗
  6. cd /tmp/app
  7. npm install
  8. node app.js
    • 啟動 express web server, port 4000

測試 REST API

  • docker exec -it fan bash
    • 進入 node 容器

      取得 Token

curl -s -X POST \
    http://localhost:4000/users \
    -H "content-type: application/x-www-form-urlencoded" \
    -d 'username=Jim&orgName=org1'

記下 token (有時效性, 過期重取) “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA"

建立 channel

  • channel 名稱 “mychannel"
curl -s -X POST \
  http://localhost:4000/channels \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json" \
  -d '{
    "channelName":"mychannel",
    "channelConfigPath":"../artifacts/channel/mychannel.tx"
}'

加入 channel

curl -s -X POST \
  http://localhost:4000/channels/mychannel/peers \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json" \
  -d '{
    "peers": ["192.168.99.100:7051","192.168.99.100:7056"]
}'

安裝 chaincode

curl -s -X POST \
  http://localhost:4000/chaincodes \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json" \
  -d '{
    "peers": ["192.168.99.100:7051","192.168.99.100:7056"],
    "chaincodeName":"mycc",
    "chaincodePath":"github.com/example_cc",
    "chaincodeVersion":"v0"
}'

啟用

curl -s -X POST \
  http://localhost:4000/channels/mychannel/chaincodes \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json" \
  -d '{
    "peers": ["192.168.99.100:7051"],
    "chaincodeName":"mycc",
    "chaincodeVersion":"v0",
    "functionName":"init",
    "args":["a","100","b","200"]
}'

Invoke request

curl -s -X POST \
  http://localhost:4000/channels/mychannel/chaincodes/mycc \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json" \
  -d '{
    "peers": ["192.168.99.100:7051", "192.168.99.100:7056"],
    "fcn":"move",
    "args":["a","b","10"]
}'

Chaincode Query

curl -s -X GET \
  "http://localhost:4000/channels/mychannel/chaincodes/mycc?peer=peer1&fcn=query&args=%5B%22a%22%5D" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json"

使用區塊編號查詢區塊資訊

  • /blocks/BlockID
curl -s -X GET \
  "http://localhost:4000/channels/mychannel/blocks/1?peer=peer1" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json"

使用 TransactionID 查詢交易

  • transactions/TxID
    • TxID 可透過 invoke chaincode 返回值取得也可透過
curl -s -X GET http://localhost:4000/channels/mychannel/transactions/bb6c007aa035cf9eb29154e6e3d90fb752d3e853adbc49c84d68385482b184be?peer=peer1 \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json"

Query ChainInfo

curl -s -X GET \
  "http://localhost:4000/channels/mychannel?peer=peer1" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json"

Query Installed chaincodes

curl -s -X GET \
  "http://localhost:4000/chaincodes?peer=peer1&type=installed" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json"

Query Instantiated chaincodes

curl -s -X GET \
  "http://localhost:4000/chaincodes?peer=peer1&type=instantiated" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json"

Query Channels

curl -s -X GET \
  "http://localhost:4000/channels?peer=peer1" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0OTk4NTUwMzcsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzEiLCJpYXQiOjE0OTk4MTkwMzd9.McFgn4pABM_uqv2vtVbU5SaLWy43OO-q_DkCsEOfcxA" \
  -H "content-type: application/json"

Read Full Post »

map 範例蠻適合快速了解 stub 有哪些 api 可用, 快速操作步驟

Read Full Post »