今天在一个新的Android项目中我遇到了这个问题。
我初始化了Firebase身份验证和数据库。
Auth工作正常。
我第一次尝试检索firebase数据库引用失败了这个logcat:
05-16 00:13:53.621 13078-13078/lorenzogangemideveloper.insurancehelper E/System: stat file error, path is /data/app/lorenzogangemideveloper.insurancehelper-1/lib/arm64, exception is android.system.ErrnoException: stat failed: ENOENT (No such file or directory) 05-16 00:13:53.716 13078-13078/lorenzogangemideveloper.insurancehelper A/FirebaseApp: Firebase API initialization failure.
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1840)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1815)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5563)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5136)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5061)
at android.app.ActivityThread.access$1600(ActivityThread.java:187)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1645)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5877)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Caused by: java.lang.NoSuchMethodError: No static method getNoBackupFilesDir(Landroid/content/Context;)Ljava/io/File; in class Lcom/google/android/gms/common/util/zzw; or its super classes (declaration of 'com.google.android.gms.common.util.zzw' appears in /data/app/lorenzogangemideveloper.insurancehelper-1/base.apk:classes33.dex)
at com.google.firebase.iid.zzh.zzeK(Unknown Source)
at com.google.firebase.iid.zzh.<init>(Unknown Source)
at com.google.firebase.iid.zzh.<init>(Unknown Source)
at com.google.firebase.iid.zzd.zzb(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1840)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1815)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5563)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5136)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5061)
at android.app.ActivityThread.access$1600(ActivityThread.java:187)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1645)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5877)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) 05-16 00:13:53.828 13078-13078/lorenzogangemideveloper.insurancehelper A/FirebaseApp: Firebase API initialization failure.
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1840)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1815)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5563)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5136)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5061)
at android.app.ActivityThread.access$1600(ActivityThread.java:187)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1645)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5877)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Caused by: java.lang.NoSuchMethodError: No static method zzyv()Lcom/google/android/gms/common/util/zze; in class Lcom/google/android/gms/common/util/zzh; or its super classes (declaration of 'com.google.android.gms.common.util.zzh' appears in /data/app/lorenzogangemideveloper.insurancehelper-1/base.apk:classes33.dex)
at com.google.android.gms.internal.zzatt.zzn(Unknown Source)
at com.google.android.gms.internal.zzatp.<init>(Unknown Source)
at com.google.android.gms.internal.zzatt.zzLP(Unknown Source)
at com.google.android.gms.internal.zzatp.zzbu(Unknown Source)
at com.google.android.gms.measurement.AppMeasurement.getInstance(Unknown Source)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1840)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1815)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5563)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5136)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5061)
at android.app.ActivityThread.access$1600(ActivityThread.java:187)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1645)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5877)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) 05-16 00:13:54.140 13078-13305/lorenzogangemideveloper.insurancehelper E/NativeCrypto: ssl=0x7f77c8b500 cert_verify_callback x509_store_ctx=0x7f6a720af8 arg=0x0 05-16 00:13:54.140 13078-13305/lorenzogangemideveloper.insurancehelper E/NativeCrypto: ssl=0x7f77c8b500 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_ECDSA 05-16 00:13:54.430 13078-13330/lorenzogangemideveloper.insurancehelper E/MPlugin: Unsupported class: com.mediatek.common.telephony.IOnlyOwnerSimSupport 05-16 00:13:54.467 13078-13328/lorenzogangemideveloper.insurancehelper E/GED: Failed to get GED Log Buf, err(0) 05-16 00:14:03.706 13078-13078/lorenzogangemideveloper.insurancehelper E/AndroidRuntime: FATAL EXCEPTION: main
Process: lorenzogangemideveloper.insurancehelper, PID: 13078
java.lang.VerifyError: Rejecting class com.google.firebase.database.FirebaseDatabase because it failed compile-time verification (declaration of 'com.google.firebase.database.FirebaseDatabase' appears in /data/app/lorenzogangemideveloper.insurancehelper-1/base.apk:classes12.dex)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at lorenzogangemideveloper.insurancehelper.compagnie.frag_lista_compagnie.onStart(frag_lista_compagnie.java:110)
at android.support.v4.app.Fragment.performStart(Fragment.java:2218)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1340)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5877)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
我试过这个解决方案,但它不起作用 - &gt; link
这是我尝试获取数据库引用的类:
public class frag_lista_compagnie extends Fragment {
//INTERFACCIA
private OnListaCompagnieFragmentInteractoinListener InterfacciaListaCompagnie;
//PARAMETRI
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
//UI
RecyclerView Recycle;
//OGGETTI
List<Compagnia> Compagnie;
Adapter_compagnie Adapter;
//DATABASE
DatabaseReference ReferenceCompagnie;
public frag_lista_compagnie() {
// Required empty public constructor
}
public static frag_lista_compagnie newInstance(String param1, String param2) {
frag_lista_compagnie fragment = new frag_lista_compagnie();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
Compagnie = new ArrayList<>();
Compagnie.add(new Compagnia());
Compagnie.add(new Compagnia());
Adapter = new Adapter_compagnie(Compagnie);
//
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.fragment_lista_compagnie, container, false);
Recycle = (RecyclerView)view.findViewById(R.id.RecycleListaCompagnie);
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if(getArguments().getString(ARG_PARAM1,"").equals("Interact"))
if (context instanceof OnListaCompagnieFragmentInteractoinListener) {
InterfacciaListaCompagnie = (OnListaCompagnieFragmentInteractoinListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
InterfacciaListaCompagnie = null;
}
@Override
public void onStart() {
super.onStart();
Recycle.setLayoutManager(new LinearLayoutManager(getContext()));
Recycle.setItemAnimator(new DefaultItemAnimator());
Recycle.setAdapter(Adapter);
ReferenceCompagnie = FirebaseDatabase.getInstance().getReference(FirebaseAuth.getInstance().getCurrentUser().getUid()
+ "/Compagnie");
ReferenceCompagnie.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists())
for(DataSnapshot compagnia: dataSnapshot.getChildren())
{
Compagnia x = (Compagnia) compagnia.getValue();
x.setKiave(compagnia.getKey());
boolean AlredyThere=false;
for(int i=0;i<Compagnie.size();i++) {
if (Compagnie.get(i).getKiave().equals(x.getKiave())) {
Compagnie.set(i, x);
AlredyThere=true;
Adapter.notifyDataSetChanged();
}
}
if(!AlredyThere) {
Compagnie.add(x);
Adapter.notifyItemInserted(Compagnie.size() - 1);
}
}
else
Log.i("ReferenceCompagnie","No data from server");
}
@Override
public void onCancelled(DatabaseError databaseError) {
Snackbar.make(getView(),R.string.errore_list_compagnie,Snackbar.LENGTH_LONG).show();
}
});
}
@Override
public void onStop() {
super.onStop();
ReferenceCompagnie.addValueEventListener(null);
}
interface OnListaCompagnieFragmentInteractoinListener {
void onFragmentInteraction(Uri uri);
} }
答案 0 :(得分:2)
打开firebase文档并检查“指南”选项卡下的“Gradle依赖关系”行。在这里,您将看到一个服务列表,比较您的实时数据库的服务版本 与list.Currently最新版本
com.google.firebase:火力数据库:10.2.6
确保build.gradle(Module:app)中的firebase-database版本与Gradle依赖项中的相同