使用' react-native-maps'
构建应用程序时出现问题这是我的setting.gradle文件
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/android')
android / app / build.gradle文件的依赖关系
dependencies {
compile project(':react-native-maps')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.airbnb.android:react-native-maps:0.6.0'
}
这是使用MapsPackage()
更新的MainActivity.java文件protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new MapsPackage()
);
}
错误即将来临:
JS服务器已经运行。 在设备上构建和安装应用程序(cd android&amp;&amp; gradlew.bat install 调试...
失败:构建因异常而失败。
出了什么问题: 配置项目&#39;:app&#39;。
时出现问题无法评估模块react-native-maps:配置名称&#39;默认&#39; ñ 找不到。
尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug运行 获得更多日志输出的选项。
建立失败
总时间:13.479秒 无法在设备上安装应用程序,请阅读上面的错误以获取详细信息。
我已经提到了给定链接https://github.com/lelandrichardson/react-native-maps/blob/master/docs/installation.md
中提到的所有程序我也见过https://github.com/lelandrichardson/react-native-maps/issues/288但无法解决错误
请帮忙 提前致谢
答案 0 :(得分:31)
错误发生在build.gradle文件的dependecies中试试这个:
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.airbnb.android:react-native-maps:0.6.0'
}
删除行compile project(':react-native-maps')
问题已解决。此行由rnpm link
创建,但是是一个错误。
在MainActivity.java中应该是这样的:
package com.yourapp; //<- put your app name
import com.facebook.react.ReactActivity;
import com.airbnb.android.react.maps.MapsPackage; //<- this line is important
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "yourapp"; //<- put your app name
}
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new MapsPackage(this) //here you must be write the param this
);
}
}
答案 1 :(得分:0)
从 react-native-maps@0.7.1 降级为 react-native-maps@0.4.2
后工作正常我正在使用 react-native@0.29.0
以下是我的设置:
android / app / build.gradle
dependencies {
compile project(':react-native-maps')
}
<强>机器人/ settings.gradle 强>
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/android')
<强> MainApplication.java 强>
package com.package;
import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.List;
import com.AirMaps.AirPackage; // <- Add this line
import com.i18n.reactnativei18n.ReactNativeI18n;
import com.oblador.vectoricons.VectorIconsPackage;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new AirPackage(), // <- Add this line
new MainReactPackage(),
new ReactNativeI18n(),
new VectorIconsPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
<强>的AndroidManifest.xml 强>
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<!--reference your google_map_id-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_map_id"/>
</application>
答案 2 :(得分:0)
我按照以下说明操作:
https://github.com/airbnb/react-native-maps/blob/master/docs/installation.md
我注明 android/settings.gradle
应指向react-native-maps/lib/android
,如下所示:
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')