不要轻易判断基于单独的标题,我知道类似的问题已经被问过,但这个问题是一个有点不同。请忍受并通读。
因此,我已经定义了一个BaseUser
类,如下所示:
import android.support.annotation.NonNull;
import android.util.Log;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.Exclude;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.storage.FirebaseStorage;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
public class BaseUser
{
private static final String TAG = "BaseUser";
/**
* Firebase Authentication and Database
*/
protected FirebaseAuth auth;
protected FirebaseFirestore db;
protected FirebaseStorage st;
/**
* General BaseUser Info
*/
private String firstName;
private String lastName;
private List<String> phones;
private List<String> emails;
private List<AddressLocation> addresses;
public BaseUser()
{
auth = FirebaseAuth.getInstance();
db = FirebaseFirestore.getInstance();
st = FirebaseStorage.getInstance();
phones = new ArrayList<>();
emails = new ArrayList<>();
addresses = new ArrayList<>();
}
/**
* Getters
*/
public final String getFirstName()
{
return firstName;
}
public final String getLastName()
{
return lastName;
}
@Exclude
public final List<String> getPhones()
{
return phones;
}
@Exclude
public final List<String> getEmails()
{
return emails;
}
@Exclude
public final List<AddressLocation> getAddresses()
{
return addresses;
}
/**
* Special Getters
*/
@Exclude
public final String getPhone(int index)
{
return phones.get(index);
}
// SimilarStuff
/**
* Setters
*/
@Exclude
public final void setFirstName(String firstName)
{
this.firstName = firstName;
}
@Exclude
public final void setLastName(String lastName)
{
this.lastName = lastName;
}
@Exclude
public final void setPhones(List<String> phones)
{
this.phones = phones;
}
@Exclude
public final void setEmails(List<String> emails)
{
this.emails = emails;
}
@Exclude
public final void setAddresses(List<AddressLocation> addresses)
{
this.addresses = addresses;
}
/**
* Special Setters
*/
@Exclude
public final void addPhone(String phone)
{
this.phones.add(phone);
}
// SimilarStuff
/**
* Authentication
*/
@Exclude
public final boolean isLoggedIn()
{
assert(auth != null);
return (auth.getCurrentUser() != null);
}
/**
* Shared BaseUser Instance
*/
protected static BaseUser holder = new BaseUser();
@Exclude
public static BaseUser getInstance()
{
assert(holder != null);
return holder;
}
/**
* Database
*/
@Exclude
protected final void downloadUser(final Callable<Void> callback)
{
// Doesn't get called for now.
}
@Exclude
protected final void uploadUser()
{
assert(isLoggedIn());
db.collection("users").document(auth.getCurrentUser().getUid()).set(this).addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
Log.wtf(TAG, "Failed to write user data");
}
});
}
}
,你可以看到,类定义了几个阵列的沿着一对夫妇串。包括绝对没有别的可能有setWallpaper
。另外,如您所见,为查找错误的来源,我从字面上排除了所有函数(是的,即使它们不是以set
或get
开始)读取两个简单字符串的函数。
现在,当调用uploadUser
方法时,出现以下错误:
java.lang.RuntimeException: Found conflicting setters with name: setWallpaper (conflicts with setWallpaper defined on android.content.ContextWrapper)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-firestore@@18.0.0:632)
at com.google.firebase.firestore.util.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-firestore@@18.0.0:348)
at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:firebase-firestore@@18.0.0:169)
at com.google.firebase.firestore.util.CustomClassMapper.access$300(com.google.firebase:firebase-firestore@@18.0.0:53)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-firestore@@18.0.0:774)
at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:firebase-firestore@@18.0.0:170)
at com.google.firebase.firestore.util.CustomClassMapper.access$300(com.google.firebase:firebase-firestore@@18.0.0:53)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-firestore@@18.0.0:774)
at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:firebase-firestore@@18.0.0:170)
at com.google.firebase.firestore.util.CustomClassMapper.access$300(com.google.firebase:firebase-firestore@@18.0.0:53)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-firestore@@18.0.0:774)
at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:firebase-firestore@@18.0.0:170)
at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:firebase-firestore@@18.0.0:101)
at com.google.firebase.firestore.util.CustomClassMapper.convertToPlainJavaTypes(com.google.firebase:firebase-firestore@@18.0.0:77)
at com.google.firebase.firestore.UserDataConverter.convertAndParseDocumentData(com.google.firebase:firebase-firestore@@18.0.0:216)
at com.google.firebase.firestore.UserDataConverter.parseSetData(com.google.firebase:firebase-firestore@@18.0.0:75)
at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:firebase-firestore@@18.0.0:174)
at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:firebase-firestore@@18.0.0:153)
at com.companyname.projectname.authentication.SignupActivity$6$1$1.onComplete(SignupActivity.java:297)
at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我grepped我的文件夹中找出包括setWallpaper
,我发现以下内容:
shell$ grep -rnw "setWallpaper" .
Binary file ./authentication/build/intermediates/transforms/instantRun/AppName/debug/0/com/companyname/projectname/authentication/ResetPasswordActivity.class matches
Binary file ./authentication/build/intermediates/transforms/instantRun/AppName/debug/0/com/companyname/projectname/authentication/WelcomeActivity.class matches
Binary file ./authentication/build/intermediates/transforms/instantRun/AppName/debug/0/com/companyname/projectname/authentication/SignupActivity.class matches
Binary file ./authentication/build/intermediates/transforms/instantRun/AppName/debug/0/com/companyname/projectname/authentication/LoginActivity.class matches
Binary file ./authentication/build/intermediates/transforms/instantRun/AppName/debug/0/com/companyname/projectname/authentication/PhoneVerificationActivity.class matches
Binary file ./authentication/build/intermediates/transforms/dexBuilder/AppName/debug/265/com/companyname/projectname/authentication/LoginActivity.dex matches
Binary file ./authentication/build/intermediates/transforms/dexBuilder/AppName/debug/265/com/companyname/projectname/authentication/WelcomeActivity.dex matches
Binary file ./authentication/build/intermediates/transforms/dexBuilder/AppName/debug/265/com/companyname/projectname/authentication/PhoneVerificationActivity.dex matches
Binary file ./authentication/build/intermediates/transforms/dexBuilder/AppName/debug/265/com/companyname/projectname/authentication/ResetPasswordActivity.dex matches
Binary file ./authentication/build/intermediates/transforms/dexBuilder/AppName/debug/265/com/companyname/projectname/authentication/SignupActivity.dex matches
Binary file ./authentication/build/intermediates/transforms/dexMerger/AppName/debug/1/classes.dex matches
因此BaseUser
与此setWallpaper
毫无关系。它仅与我的UI活动有关(无论如何我都没有明确使用它)。
BaseUser
类本身处理Firestore可能会引起问题,因此我尝试从类外部进行同样的操作。一样。BaseUser
。我已经全部禁用了。相同。 (我什至不确定为什么会有问题!)我不确定以下内容是否相关,但是考虑到该错误的怪异性质,无论如何我都会将其扔到这里。
类BaseUser
是在被称为一个单独的模块user
。处理身份验证的UI类(在上面的grep
输出中列出)位于称为authentication
的单独模块中。第三模块core
定义了火力库依赖并从必要的信息google-services.json
。
我还必须提到,与模块的这种构造我可以使用火力地堡认证就好了。只有Firestore或Firebase数据库有问题。
现在,为什么人人都在抱怨Firestore什至没有我班上的二传手?我该如何解决?
我试图两个不同的东西现在:
我试图上载一个简单的地图,而不是,所以uploadUser
函数内部添加以下:
protected final void uploadUser()
{
assert(isLoggedIn());
Map<String, Object> city = new HashMap<>();
city.put("name", "Los Angeles");
city.put("state", "CA");
city.put("country", "USA");
db.collection("users").document(auth.getCurrentUser().getUid()).set(city);
}
哪些工作正常,然后我尝试添加一个简单的类作为要上传的对象。如下:
protected final void uploadUser()
{
class Stupid {
public String name;
public String email;
public Stupid()
{
}
public Stupid(String name, String email)
{
this.name = name;
this.email = email;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
}
Stupid stupid = new Stupid("Name", "Email");
db.collection("users").document(auth.getCurrentUser().getUid()).set(stupid);
}
再次,我给setWallpaper
带来了同样的错误。我还尝试了使用整数而不是字符串的Stupid类的另一个变体。也一样愚蠢的简单的POJO类。这件事到底有什么问题?我之前用所有的时间来使用类和对象与火力地堡数据库。在这种情况下我想念什么?
答案 0 :(得分:0)
好吧,所以我做了两件事,不确定是哪一个修复了它(也许都是吗?!)
以前,我是在检查Google Play服务的可用性。因此,为此,我加入了com.google.android.gms:play-services-base:16.1.0
。导致我收到错误Error: Cannot fit requested classes in a single dex file. Try supplying a main-dex list. # methods: 72477 > 65536
。我的解决方案是添加multiDexEnable 'true'
。我现在要做的是改为遵循this answer。因此,我删除了所有多dex内容,并改用com.google.android.gms:play-services-gcm:16.0.0
。
我做的第二件事是禁用即时运行。
现在,我拥有的相同代码的工作原理就像一个超级按钮,可以在Firestore中读取/写入。
我对发生的事情没有任何解释。但是问题现在消失了。