为 React-Native 构建 Android 模块时找不到符号 getCurrentActivity

Cannot find symbol getCurrentActivity when building an Android module for React-Native

First of all, here is a test repo to replicate my issue

你好, 我正在尝试为 React-Native 创建一个简单的 Android 模块,但我在从 Java 代码获取当前 Activity 时遇到了一些问题。

这不是我处理的第一个本机模块,但从今天起我再也不需要获得 Activity 参考。

interested module是连接Estimote SDK的桥梁,但这与问题无关。
Android studio 中的模块运行良好,但是当我尝试使用 react-native run android 构建它时,出现以下错误:

:react-native-estimote-android:compileReleaseJavaWithJavac
/Users/matteo/dev/react-native-example/react-native-estimote-android/android/src/main/java/com/mmazzarolo/estimoteandroid/EstimoteAndroidModule.java:64: error: cannot find symbol
        Activity currentActivity = this.getCurrentActivity();
                                       ^
  symbol: method getCurrentActivity()
1 error
:react-native-estimote-android:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

根据我的理解,扩展 ReactContextBaseJavaModule 应该足以让我使用 this.getCurrentActivity()(Android studio 同意我的观点)。

这是我已经尝试过的:
- 实施 ActivityEventListener:当我尝试导入 ActivityEventListener;
时出现同样的 找不到符号 错误 - android/.gradlew clean
- watchman watch-del-all && rm -rf node_modules/ && npm cache clean && npm prune && npm i
- 在两台不同的计算机上尝试了相同的 repo...

有什么提示吗? 提前谢谢你。

 @ReactMethod
public void start(final Callback callback) {
    Activity currentActivity = getCurrentActivity();
    this.mBeaconManager.connect(new BeaconManager.ServiceReadyCallback() {
        @Override
        public void onServiceReady() {
            mBeaconManager.startRanging(region);
            callback.invoke();
        }
    });
}

从启动方法中删除它,如果你这样做 this.getCurrentActivity() 它将引用 Estimote Android 模块上下文而不是应用程序 ReactContextBaseJavaModule 上下文

问题出在模块 'react-native-estimote-android'

中的 react-native 版本

只需将compile 'com.facebook.react:react-native:0.12.+'改为 compile 'com.facebook.react:react-native:+'

这将解决找不到 getCurrentActivity 符号的问题。

getCurrentActivity 方法在 react-native 0.12 版本中不可用。这就是它抛出错误的原因。