我尝试了互联网上提供的所有解决方案,但无法解决此问题。请帮我解决这个例外。它不允许我在我的项目中添加任何Java类。
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.firza.map"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.android.support:design:23.4.0'
}
MapsActivity.java
public class MapsActivity extends Fragment implements OnMapReadyCallback,View.OnClickListener {
private GoogleMap mMap;
MapView mapView;
Button btn_rest;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view =LayoutInflater.from(getActivity()).inflate(R.layout.activity_maps,null);
mapView=(MapView) view.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
btn_rest=(Button) view.findViewById(R.id.btn_rest);
btn_rest.setOnClickListener(this);
return view;
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
@Override
public void onClick(View v) {
Log.i("okkkk","ojooooooo ");
}
}
异常
02-12 19:04:56.737 23160-23160/com.example.firza.map E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.firza.map, PID: 23160
java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1656)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1627)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5020)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534)
at android.app.ActivityThread.access$1600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5304)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
请勿导入整个Google Play服务库,只导入您需要的依赖项。 浏览此列表,找出您需要的内容。 https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project 您需要在FirebaseOptions类所在的位置添加firebase依赖项。
compile "com.google.firebase:firebase-core:10.0.1"
导入完整依赖项不是一个好习惯,因为您可能达到最大方法计数(dex计数)。
答案 1 :(得分:1)
您正在使用 GoogleMap ,然后最好拨打 play-services-maps ,而不是播放服务。< / p>
<强>唐&#39;吨强>
compile 'com.google.android.gms:play-services:10.0.1'
<强>不要强>
compile 'com.google.android.gms:play-services-maps:10.0.1' // or 9.8.0
答案 2 :(得分:0)
您在build.gradle
中缺少firebase依赖项。例如
compile "com.google.firebase:firebase-core:$PLAY_SERVICES_VERSION"
compile "com.google.firebase:firebase-database:$PLAY_SERVICES_VERSION"
答案 3 :(得分:0)
根据此链接的firebase文档 https://firebase.google.com/docs/android/setup, 您必须在模块Gradle文件中添加 Firebase SDK 依赖项和apply 插件行。
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-core:10.0.1'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'