Tencent / VasDolly

Android V1 and V2 Signature Channel Package Plugin
Other
3.06k stars 385 forks source link

Can not get by react-native #87

Closed echokk11 closed 5 years ago

echokk11 commented 5 years ago
  1. doing all steps in README.
  2. add 2 java class ChannelModule, ChannelPackage
public class ChannelModule extends ReactContextBaseJavaModule {

    private String channel;
    public ChannelModule(ReactApplicationContext reactContext) {
        super(reactContext);
        channel = ChannelReaderUtil.getChannel(reactContext);
    }

    @Override
    public String getName() {
        return "ChannelModule";
    }

    @ReactMethod
    public String getChannel() {
        return channel;
    }
}
public class ChannelPackage implements ReactPackage {

    @Override
    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
        List<NativeModule> modules = new ArrayList<>();
        modules.add(new ChannelModule(reactContext));
        return modules;
    }

    @Override
    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return Collections.emptyList();
    }
}
  1. add new ChannelPackage() to MainApplication

    @Override
    protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    ...
    new ChannelPackage()
    );
    }
  2. in JavaScript.

    
    import { NativeModules } from "react-native";

const channel = NativeModules.ChannelModule.getChannel();

but i got `undefined`

### this is my release apk
<img width="318" alt="image" src="https://user-images.githubusercontent.com/8499152/60655806-f67e8500-9e80-11e9-9d64-92ade2eae8f0.png">

### this is parts of log

generateV2ChannelApk , channel = robot , apkChannelName = app-1.0-1-robot-release.apk addIdValueByteBufferMap , new IdValueMap = {-2012129793=java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]} find V2 signature block Id : 1896449818 addIdValueByteBufferMap , existed IdValueMap = {1896449818=java.nio.HeapByteBuffer[pos=0 lim=1545 cap=1545], 1114793335=java.nio.HeapByteBuffer[pos=0 lim=2495 cap=2495]} addIdValueByteBufferMap , final IdValueMap = {1896449818=java.nio.HeapByteBuffer[pos=0 lim=1545 cap=1545], 1114793335=java.nio.HeapByteBuffer[pos=0 lim=2495 cap=2495], -2012129793=java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]} generateApkSigningBlock , needPadding = true generateApkSigningBlock , final length = 4088 padding = 2490 bufferSize = 2478 addIdValueByteBufferMap , oldApkSigningBlock size = 4096 , newApkSigningBlock size = 4096 addIdValueByteBufferMap , after add channel , new apk is /Users/x/ideaprojects/y/android/app/build/channel/release/app-1.0-1-robot-release.apk , length = 12990563 try to read channel info from apk : /Users/x/ideaprojects/y/android/app/build/channel/release/app-1.0-1-robot-release.apk find V2 signature block Id : 1896449818 getByteBufferValueById , destApk /Users/x/ideaprojects/y/android/app/build/channel/release/app-1.0-1-robot-release.apk IdValueMap = {1896449818=java.nio.HeapByteBuffer[pos=0 lim=1545 cap=1545], -2012129793=java.nio.HeapByteBuffer[pos=0 lim=5 cap=5], 1114793335=java.nio.HeapByteBuffer[pos=0 lim=2478 cap=2478]} getByteValueById , id = -2012129793 , value = java.nio.HeapByteBuffer[pos=0 lim=5 cap=5] generateV2ChannelApk , /Users/x/ideaprojects/y/android/app/build/channel/release/app-1.0-1-robot-release.apk add channel success verified : true Verified using v1 scheme (JAR signing): true Verified using v2 scheme (APK Signature Scheme v2): true generateV2ChannelApk , after add channel , apk /Users/x/ideaprojects/y/android/app/build/channel/release/app-1.0-1-robot-release.apk v2 verify success


### success using VasDolly.jar CLI

java -jar VasDolly.jar get -c xxx.apk

could get the channel


Did I make some mistakes ?
echokk11 commented 5 years ago

I reslove it myself.

React-native nativeModules can not return things. Only use Callback or Promise

@ReactMethod
public void getChannel(Promise promise) {
  promise.resolve(channel);
}

then in js

NativeModules.ChannelModule.getChannel().then(c => {
  // got c
})