fix bugs related to release build for android devices

This commit is contained in:
Roman Volosovskyi 2016-10-24 23:46:06 +03:00
parent b60c15988b
commit 53e7ca91d9
30 changed files with 178 additions and 101 deletions

View File

@ -1,7 +1,7 @@
{
"name": "StatusIm",
"interface": "reagent",
"androidHost": "localhost",
"androidHost": "10.0.3.2",
"modules": [
"react-native-contacts",
"react-native-invertible-scroll-view",
@ -28,7 +28,10 @@
"react-native-image-crop-picker",
"react-native-webview-bridge",
"react-native-drawer-layout",
"homoglyph-finder"
"homoglyph-finder",
"web3",
"eccjs",
"chance"
],
"imageDirs": [
"images"

View File

@ -58,6 +58,9 @@ import com.android.build.OutputFile
* inputExcludes: ["android/**", "ios/**"]
* ]
*/
project.ext.react = [
nodeExecutableAndArgs: ["node", "--max-old-space-size=4096"]
]
apply from: "../../node_modules/react-native/react.gradle"
@ -90,6 +93,14 @@ android {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
splits {
abi {
reset()
@ -102,6 +113,7 @@ android {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release

View File

@ -32,21 +32,28 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@Override
public void onHostResume() { // Actvity `onResume`
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
Log.d(TAG, "On host Activity doesn't exist");
return;
}
if (status == null) {
status = new StatusConnector(currentActivity, StatusService.class);
status.registerHandler(this);
}
status.bindService();
WritableMap params = Arguments.createMap();
Log.d(TAG, "Send module.initialized event");
params.putString("jsonEvent", "{\"type\":\"module.initialized\"}");
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("gethEvent", params);
}
@Override
public void onHostPause() { // Actvity `onPause`
if (status != null) {
status.unbindService();
}
@ -54,7 +61,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@Override
public void onHostDestroy() { // Actvity `onDestroy`
if (status != null) {
status.stopNode(null);
}
@ -126,7 +132,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void startNode(Callback callback) {
Log.d(TAG, "startNode");
if (!checkAvailability()) {
callback.invoke(false);
return;
@ -140,7 +146,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void login(String address, String password, Callback callback) {
Log.d(TAG, "login");
if (!checkAvailability()) {
callback.invoke(false);
return;
@ -154,7 +160,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void createAccount(String password, Callback callback) {
Log.d(TAG, "createAccount");
if (!checkAvailability()) {
callback.invoke(false);
return;
@ -168,7 +174,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void recoverAccount(String passphrase, String password, Callback callback) {
Log.d(TAG, "recoverAccount");
if (!checkAvailability()) {
callback.invoke(false);
return;
@ -186,7 +192,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void completeTransaction(String hash, String password, Callback callback) {
Log.d(TAG, "completeTransaction");
if (!checkAvailability()) {
callback.invoke(false);
return;
@ -203,7 +209,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void initJail(String js, Callback callback) {
Log.d(TAG, "initJail");
if (!checkAvailability()) {
callback.invoke(false);
return;
@ -217,7 +223,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void parseJail(String chatId, String js, Callback callback) {
Log.d(TAG, "parseJail");
if (!checkAvailability()) {
callback.invoke(false);
return;
@ -231,7 +237,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void callJail(String chatId, String path, String params, Callback callback) {
Log.d(TAG, "callJail");
if (!checkAvailability()) {
callback.invoke(false);
return;
@ -245,7 +251,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void setAdjustResize() {
Log.d(TAG, "setAdjustResize");
final Activity activity = getCurrentActivity();
if (activity == null) {
return;
@ -261,7 +267,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void setAdjustPan() {
Log.d(TAG, "setAdjustPan");
final Activity activity = getCurrentActivity();
if (activity == null) {
return;
@ -277,7 +283,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
@ReactMethod
public void setSoftInputMode(final int mode) {
Log.d(TAG, "setSoftInputMode");
final Activity activity = getCurrentActivity();
if (activity == null) {
return;

View File

@ -13,10 +13,12 @@
"assert": "^1.4.1",
"awesome-phonenumber": "^1.0.13",
"browserify-zlib": "^0.1.4",
"chance": "1.0.4",
"console-browserify": "^1.1.0",
"constants-browserify": "0.0.1",
"dns.js": "^1.0.1",
"domain-browser": "^1.1.7",
"eccjs": "0.3.1",
"events": "^1.1.1",
"homoglyph-finder": "^1.1.1",
"https-browserify": "0.0.1",
@ -28,7 +30,7 @@
"querystring-es3": "^0.2.1",
"re-natal": "0.2.38",
"react": "^15.3.1",
"react-native": "^0.33.0",
"react-native": "^0.34.0",
"react-native-action-button": "^1.1.11",
"react-native-android-sms-listener": "github:adrian-tiberius/react-native-android-sms-listener#listener-bugfix",
"react-native-camera": "git+https://github.com/lwansbrough/react-native-camera.git",
@ -58,7 +60,8 @@
"timers-browserify": "^1.4.2",
"tty-browserify": "0.0.0",
"url": "^0.10.3",
"vm-browserify": "0.0.4"
"vm-browserify": "0.0.4",
"web3": "0.16.0"
},
"browser": {
"crypto": "react-native-crypto",

View File

@ -11,12 +11,9 @@
[natal-shell "0.3.0"]
[com.andrewmcveigh/cljs-time "0.4.0"]
[tailrecursion/cljs-priority-map "1.2.0"]
[cljsjs/web3 "0.16.0-0"]
[com.taoensso/timbre "4.7.4"]
[org.clojure/test.check "0.9.0"]
[cljsjs/chance "0.7.3-0"]
[cljsjs/eccjs "0.3.1-0"]]
:plugins [[lein-cljsbuild "1.1.1"]
[org.clojure/test.check "0.9.0"]]
:plugins [[lein-cljsbuild "1.1.4"]
[lein-figwheel "0.5.0-2"]]
:clean-targets ["target/" "index.ios.js" "index.android.js"]
:aliases {"prod-build" ^{:doc "Recompile code with prod profile."}
@ -55,13 +52,21 @@
:optimizations :none
:target :nodejs}}}}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
:prod {:cljsbuild {:builds {:ios {:source-paths ["src" "env/prod"]
:compiler {:output-to "index.ios.js"
:main "env.ios.main"
:output-dir "target/ios"
:optimizations :simple}}
:android {:source-paths ["src" "env/prod"]
:compiler {:output-to "index.android.js"
:main "env.android.main"
:output-dir "target/android"
:optimizations :simple}}}}}})
:prod {:cljsbuild {:builds [{:id "ios"
:source-paths ["src" "env/prod"]
:compiler {:output-to "index.ios.js"
:main "env.ios.main"
:output-dir "target/ios"
:static-fns true
:optimize-constants true
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}
{:id "android"
:source-paths ["src" "env/prod"]
:compiler {:output-to "index.android.js"
:main "env.android.main"
:output-dir "target/android"
:static-fns true
:optimize-constants true
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}]}}})

View File

@ -1,6 +1,5 @@
(ns status-im.accounts.recover.validations
(:require [cljs.spec :as s]
[cljsjs.web3]))
(:require [cljs.spec :as s]))
(s/def ::not-empty-string (s/and string? not-empty))
(s/def ::passphrase ::not-empty-string)

View File

@ -105,10 +105,10 @@
(defn init [& [env]]
(dispatch-sync [:reset-app])
(.registerComponent app-registry "StatusIm" #(r/reactify-component app-root)
(dispatch [:listen-to-network-status!])
(dispatch [:initialize-crypt])
(dispatch [:initialize-geth])
(status/set-soft-input-mode status/adjust-resize)
(dispatch [:load-user-phone-number])
(init-back-button-handler!)
(.registerComponent app-registry "StatusIm" #(r/reactify-component app-root)))
(init-back-button-handler!)))

View File

@ -34,7 +34,7 @@
;; Dialogs
(def react-native-dialogs (u/require "react-native-dialogs"))
(def react-native-dialogs (js/require "react-native-dialogs"))
(defn show-dialog [{:keys [title options callback]}]
(let [dialog (new react-native-dialogs)]

View File

@ -5,14 +5,14 @@
:refer [get-react-property get-class adapt-class]]
[status-im.utils.platform :refer [platform-specific]]))
(def react-native (u/require "react-native"))
(def react-native (js/require "react-native"))
(def native-modules (.-NativeModules react-native))
(def device-event-emitter (.-DeviceEventEmitter react-native))
(def linear-gradient-module (u/require "react-native-linear-gradient"))
(def dismiss-keyboard! (u/require "dismissKeyboard"))
(def orientation (u/require "react-native-orientation"))
(def drawer (u/require "react-native-drawer-layout"))
(def linear-gradient-module (js/require "react-native-linear-gradient"))
(def dismiss-keyboard! (js/require "dismissKeyboard"))
(def orientation (js/require "react-native-orientation"))
(def drawer (js/require "react-native-drawer-layout"))
;; React Components
@ -101,7 +101,7 @@
;; Image picker
(def image-picker-class (u/require "react-native-image-crop-picker"))
(def image-picker-class (js/require "react-native-image-crop-picker"))
(defn show-image-picker [images-fn]
(let [image-picker (.-default image-picker-class)]

View File

@ -1,9 +1,44 @@
(ns status-im.components.status
(:require-macros [status-im.utils.slurp :refer [slurp]])
(:require-macros [status-im.utils.slurp :refer [slurp]]
[cljs.core.async.macros :refer [go-loop go]])
(:require [status-im.components.react :as r]
[status-im.utils.types :as t]
[re-frame.core :refer [dispatch]]
[taoensso.timbre :as log]))
[taoensso.timbre :as log]
[cljs.core.async :refer [<! timeout]]))
;; if StatusModule is not initialized better to store
;; calls and make them only when StatusModule is ready
;; this flag helps to handle this
(defonce module-initialized? (atom js/goog.DEBUG))
;; array of calls to StatusModule
(defonce calls (atom []))
(defn module-initialized! []
(reset! module-initialized? true))
(defn store-call [args]
(log/debug :store-call args)
(swap! calls conj args))
(defn call-module [f]
(log/debug :call-module)
(if @module-initialized?
(f)
(store-call f)))
(defonce loop-started (atom false))
(when-not @loop-started
(go-loop [_ nil]
(reset! loop-started true)
(if (and (seq @calls) @module-initialized?)
(do (swap! calls (fn [calls]
(doseq [call calls]
(call))))
(reset! loop-started false))
(recur (<! (timeout 500))))))
(def status-js (slurp "resources/status.js"))
@ -11,55 +46,59 @@
(when (exists? (.-NativeModules r/react-native))
(.-Status (.-NativeModules r/react-native))))
(when status
(defn init-jail []
(.initJail status status-js #(log/debug "jail initialized")))
(when status (call-module init-jail))
(.addListener r/device-event-emitter "gethEvent"
#(dispatch [:signal-event (.-jsonEvent %)]))
(defn start-node [on-result]
(when status
(.startNode status on-result)))
(call-module #(.startNode status on-result))))
(defn create-account [password on-result]
(when status
(.createAccount status password on-result)))
(call-module #(.createAccount status password on-result))))
(defn recover-account [passphrase password on-result]
(when status
(.recoverAccount status passphrase password on-result)))
(call-module #(.recoverAccount status passphrase password on-result))))
(defn login [address password on-result]
(when status
(.login status address password on-result)))
(call-module #(.login status address password on-result))))
(defn complete-transaction
[hash password callback]
(log/debug :complete-transaction (boolean status) hash password)
(when status
(.completeTransaction status hash password callback)))
(call-module #(.completeTransaction status hash password callback))))
(defn parse-jail [chat-id file callback]
(when status
(.parseJail status chat-id file callback)))
(call-module #(.parseJail status chat-id file callback))))
(defn cljs->json [data]
(.stringify js/JSON (clj->js data)))
(defn call-jail [chat-id path params callback]
(when status
(log/debug :chat-id chat-id)
(log/debug :path path)
(log/debug :params params)
(let [cb (fn [r]
(let [r' (t/json->clj r)]
(log/debug r')
(callback r')))]
(.callJail status chat-id (cljs->json path) (cljs->json params) cb))))
(call-module
#(do
(log/debug :chat-id chat-id)
(log/debug :path path)
(log/debug :params params)
(let [cb (fn [r]
(let [r' (t/json->clj r)]
(log/debug r')
(callback r')))]
(.callJail status chat-id (cljs->json path) (cljs->json params) cb))))))
(defn set-soft-input-mode [mode]
(when status
(.setSoftInputMode status mode)))
(call-module #(.setSoftInputMode status mode))))
(def adjust-resize 16)
(def adjust-pan 32)

View File

@ -3,7 +3,7 @@
[reagent.core :as r]))
(def webview-bridge-class
(r/adapt-react-class (u/require "react-native-webview-bridge")))
(r/adapt-react-class (js/require "react-native-webview-bridge")))
(defn webview-bridge [opts]
[webview-bridge-class opts])

View File

@ -77,7 +77,7 @@
(register-handler :load-contacts load-contacts!)
;; TODO see https://github.com/rt2zz/react-native-contacts/issues/45
(def react-native-contacts (require "react-native-contacts"))
(def react-native-contacts (js/require "react-native-contacts"))
(defn contact-name [contact]
(->> contact

View File

@ -1,10 +1,11 @@
(ns status-im.contacts.validations
(:require [cljs.spec :as s]
[cljsjs.web3]
[status-im.data-store.contacts :as contacts]))
(def web3 (js/require "web3"))
(defn is-address? [s]
(.isAddress js/Web3.prototype s))
(.isAddress web3.prototype s))
(defn unique-identity? [identity]
(not (contacts/exists? identity)))

View File

@ -8,7 +8,7 @@
[clojure.string :as str])
(:refer-clojure :exclude [exists?]))
(def realm-class (u/require "realm"))
(def realm-class (js/require "realm"))
(defn realm-version
[file-name]

View File

@ -75,6 +75,8 @@
(dispatch [:init-wallet-chat])
(dispatch [:load-commands! console-chat-id]))))
(def ecc (js/require "eccjs"))
(register-handler :initialize-crypt
(u/side-effect!
(fn [_ _]
@ -87,8 +89,8 @@
:error error}]))
(do
(->> (.toString buffer "hex")
(.toBits (.. js/ecc -sjcl -codec -hex))
(.addEntropy (.. js/ecc -sjcl -random)))
(.toBits (.. ecc -sjcl -codec -hex))
(.addEntropy (.. ecc -sjcl -random)))
(dispatch [:crypt-initialized]))))))))
(defn node-started [db result]
@ -96,9 +98,9 @@
(register-handler :initialize-geth
(u/side-effect!
(fn [db _]
(log/debug "Starting node")
(status/start-node (fn [result] (node-started db result))))))
(fn [db _]
(log/debug "Starting node")
(status/start-node (fn [result] (node-started db result))))))
(register-handler :signal-event
(u/side-effect!
@ -108,8 +110,14 @@
(case type
"transaction.queued" (dispatch [:transaction-queued event])
"node.started" (log/debug "Event *node.started* received")
"module.initialized" (dispatch [:status-module-initialized!])
(log/debug "Event " type " not handled"))))))
(register-handler :status-module-initialized!
(u/side-effect!
(fn [db]
(status/module-initialized!))))
(register-handler :crypt-initialized
(u/side-effect!
(fn [_ _]

View File

@ -3,7 +3,7 @@
[status-im.translations.en :as en]
[status-im.utils.utils :as u]))
(def i18n (u/require "react-native-i18n"))
(def i18n (js/require "react-native-i18n"))
(set! (.-fallbacks i18n) true)
(set! (.-defaultSeparator i18n) "/")
@ -26,4 +26,4 @@
(name)
(str "t/status-")
(keyword)
(label)))
(label)))

View File

@ -40,7 +40,7 @@
;; Dialogs
(def react-native (u/require "react-native"))
(def react-native (js/require "react-native"))
(defn show-action-sheet [{:keys [options callback cancel-text]}]
(.showActionSheetWithOptions (.-ActionSheetIOS react-native)

View File

@ -1,21 +1,21 @@
(ns status-im.protocol.encryption
(:require [cljsjs.chance]
[cljsjs.eccjs]))
(ns status-im.protocol.encryption)
(def default-curve 384)
(def ecc (js/require "eccjs"))
(defn new-keypair!
"Returns {:private \"private key\" :public \"public key\""
[]
(let [{:keys [enc dec]}
(-> (.generate js/ecc (.-ENC_DEC js/ecc) default-curve)
(-> (.generate ecc (.-ENC_DEC ecc) default-curve)
(js->clj :keywordize-keys true))]
{:private dec
:public enc}))
(defn encrypt [public-key content]
(.encrypt js/ecc public-key content))
(.encrypt ecc public-key content))
(defn decrypt [private-key content]
(.decrypt js/ecc private-key content))
(.decrypt ecc private-key content))

View File

@ -1,9 +1,9 @@
(ns status-im.protocol.web3.utils
(:require cljsjs.web3
[cljs-time.core :refer [now]]
(:require [cljs-time.core :refer [now]]
[cljs-time.coerce :refer [to-long]]))
(def web3 js/Web3)
(def web3 (js/require "web3"))
(def status-app-topic "status-app")
(defn from-utf8 [s]

View File

@ -5,7 +5,6 @@
[status-im.utils.handlers :as u]
[status-im.utils.types :as t]
[status-im.components.status :as status]
cljsjs.web3
[clojure.string :as s]
[taoensso.timbre :as log]))

View File

@ -11,8 +11,7 @@
[status-im.components.styles :refer [icon-ok
icon-close]]
[status-im.transactions.styles :as st]
[status-im.i18n :refer [label label-pluralize]]
cljsjs.web3))
[status-im.i18n :refer [label label-pluralize]]))
(defn title-bar [title id]
[view st/title-bar

View File

@ -4,7 +4,7 @@
[status-im.utils.utils :as u])
(:import goog.crypt.Sha256))
(def random-bytes (u/require "react-native-randombytes"))
(def random-bytes (js/require "react-native-randombytes"))
(def sha-256 (Sha256.))

View File

@ -2,7 +2,7 @@
(:require [clojure.string :as s]
[status-im.utils.utils :as u]))
(def fs (u/require "react-native-fs"))
(def fs (js/require "react-native-fs"))
(defn move-file [src dst handler]
(let [result (.moveFile fs src dst)
@ -13,4 +13,4 @@
(defn read-file [path encoding on-read on-error]
(-> (.readFile fs path encoding)
(.then on-read)
(.catch on-error)))
(.catch on-error)))

View File

@ -1,7 +1,7 @@
(ns status-im.utils.homoglyph
(:require [status-im.utils.utils :as u]))
(def homoglyph-finder (u/require "homoglyph-finder"))
(def homoglyph-finder (js/require "homoglyph-finder"))
(defn matches [s1 s2]
(.isMatches homoglyph-finder s1 s2))

View File

@ -4,7 +4,7 @@
(def default-size 40)
(def identicon-js (u/require "identicon.js"))
(def identicon-js (js/require "identicon.js"))
(defn identicon
([hash] (identicon hash default-size))

View File

@ -1,10 +1,10 @@
(ns status-im.utils.phone-number
(:require [status-im.utils.utils :as u]))
(def i18n (u/require "react-native-i18n"))
(def i18n (js/require "react-native-i18n"))
(def locale (or (.-locale i18n) "___en"))
(def country-code (subs locale 3 5))
(def awesome-phonenumber (u/require "awesome-phonenumber"))
(def awesome-phonenumber (js/require "awesome-phonenumber"))
;; todo check wrong numbers, .getNumber returns empty string
(defn format-phone-number [number]

View File

@ -3,7 +3,7 @@
[status-im.android.platform :as android]
[status-im.ios.platform :as ios]))
(def react-native (u/require "react-native"))
(def react-native (js/require "react-native"))
(def platform
(when-let [pl (.-Platform react-native)]
@ -16,4 +16,4 @@
(cond
android? android/platform-specific
ios? ios/platform-specific
:else {}))
:else {}))

View File

@ -1,8 +1,11 @@
(ns status-im.utils.random
(:require [cljsjs.chance]))
(ns status-im.utils.random)
(defn timestamp []
(.getTime (js/Date.)))
(def Chance (js/require "chance"))
(def chance (Chance.))
(defn id []
(str (timestamp) "-" (.guid js/chance)))
(str (timestamp) "-" (.guid chance)))

View File

@ -2,7 +2,7 @@
(:require [status-im.utils.platform :refer [android?]]
[status-im.utils.utils :as u]))
(def sms-listener (.-default (u/require "react-native-android-sms-listener")))
(def sms-listener (.-default (js/require "react-native-android-sms-listener")))
;; Only android is supported!

View File

@ -12,7 +12,7 @@
(defn log [obj]
(.log js/console obj))
(def react-native (require "react-native"))
(def react-native (js/require "react-native"))
(defn show-popup [title content]
(.alert (.-Alert react-native)