由于错误“我发现与操作系统无关的路径'META-INF / LICENSE'找到多个文件”后,我删除了Firebase数据库库的库依赖文件。 所以我添加了配置文件,它可以编译,但显示另一个错误 它没有编译,所以我尝试添加firebase实时数据库的库依赖项,但是找不到符号类
// gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.one4all.Sumo"
minSdkVersion 22
targetSdkVersion 28
versionCode 7
versionName "1.3.5"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
defaultConfig {
multiDexEnabled true
}
packagingOptions {
pickFirst 'META-INF/*'
}
}
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// implementation files('libs/json-simple-1.1.1.jar')
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'com.android.support:cardview-v7'
// implementation
implementation 'com.android.support:support-v4:28.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'com.google.firebase:firebase-storage:19.0.0'
implementation 'com.firebaseui:firebase-ui-storage:3.2.2'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:19.0.0'
//Admin
implementation 'com.google.firebase:firebase-admin:6.10.0'
//firebase Admin
// implementation 'com.google.firebase:firebase-admin:6.10.0'
// implementation 'com.github.bumptech.glide:glide:4.9.0'
// annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
// implementation "com.xwray:groupie:2.5.1"
// implementation "com.xwray:groupie-kotlin-android-extensions:2.5.1"
}
apply plugin: 'com.google.gms.google-services'
repositories {
mavenCentral()
}
//
java文件
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
import androidx.annotation.NonNull;//master branch
public class SignInWithGoogle extends BaseActivity implements
View.OnClickListener {
private static final String TAG = "GoogleActivity";
private static final int RC_SIGN_IN = 9001;
// [START declare_auth]
private FirebaseAuth mAuth;
// [END declare_auth]
private GoogleSignInClient mGoogleSignInClient;
private TextView mStatusTextView;
private TextView mDetailTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in_with_google);
;
// Views
mStatusTextView = findViewById(R.id.status);
mDetailTextView = findViewById(R.id.detail);
// Button listeners
findViewById(R.id.signInButton).setOnClickListener(this);
findViewById(R.id.signOutButton).setOnClickListener(this);
findViewById(R.id.disconnectButton).setOnClickListener(this);
// [START config_signin]
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.client))//if not works default_web_client_id
.requestEmail()
.build();
// [END config_signin]
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
// [START initialize_auth]
// Initialize Firebase Auth
mAuth = FirebaseAuth.getInstance();
// [END initialize_auth]
}
// [START on_start_check_user]
@Override
public void onStart() {
super.onStart();
// Check if userListFragment is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
updateUI(currentUser);
}
// [END on_start_check_user]
// [START onactivityresult]
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
Log.i("loging","login succeful");
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.i("loging","login was notsucceful");
Log.w(TAG, "Google sign in failed", e);
Toast.makeText(SignInWithGoogle.this,"sign in was not succeful",Toast.LENGTH_SHORT).show();
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
}
}
// [END onactivityresult]
// [START auth_with_google]
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
// [START_EXCLUDE silent]
showProgressDialog();
// [END_EXCLUDE]
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in userListFragment's information
Intent intent = new Intent(SignInWithGoogle.this,MainChatActivity.class);
startActivity(intent);
Log.d(TAG, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the userListFragment.
Log.w(TAG, "signInWithCredential:failure", task.getException());
Snackbar.make(findViewById(R.id.main_layout), "Authentication Failed.", Snackbar.LENGTH_SHORT).show();
updateUI(null);
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
}
在其他注册活动类中
public void createFireBaseUser(){
String email = mEmailView.getText().toString();
String password = mPasswordView.getText().toString();
firebaseAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("sumo","sumo created");
if (!task.isSuccessful()){
showErrorDialog("Email already exists");
}else {
saveName();
Intent intent = new Intent(RegisterActivity.this,LoginActivity.class);
finish();
startActivity(intent);
}
}
});
错误:找不到符号变量GoogleAuthProvider
错误:找不到符号类AuthResult
错误:找不到符号类AuthResult
错误:找不到符号类FirebaseUser
错误:找不到符号类AuthCredential
答案 0 :(得分:1)
我遇到相同的问题,首先尝试删除导致问题的所有依赖项,然后在重建项目后导入项目,然后清理项目。希望这会有所帮助。