Estou desenvolvendo um aplicativo com o Android Studio versão 3.0 Canary, porém estou passando por um problema chato.
Tenho como activity inicial com o login através do Facebook. Já gerei a chave release pra validar o login.
O erro ocorre quando gero um apk
em modo debug, o aplicativo abre normalmente na activity login, mas quando compilo um apk
no modo release, dá o erro abaixo e logo depois fecha automaticamente.:
O aplicativo parou
Vi que em alguns celulares o apk
release abre e em outros não. Meu celular é Moto G versao 5.0.
Activity Login:
public class MainLoginActivity extends AppCompatActivity {
private LoginButton loginButton;
private CallbackManager callbackManager;
private FirebaseAuth firebaseAuth;
private FirebaseAuth.AuthStateListener firebaseAuthListener;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity_main_login );
progressBar = (ProgressBar) findViewById(R.id.progressBar);
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.loginButton);
loginButton.setReadPermissions( Arrays.asList("email"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(), R.string.cancel_login, Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {
Toast.makeText(getApplicationContext(), R.string.error_login, Toast.LENGTH_SHORT).show();
}
});
firebaseAuth = FirebaseAuth.getInstance();
firebaseAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
goMainScreen();
}
}
};
}
private void handleFacebookAccessToken(AccessToken accessToken) {
progressBar.setVisibility( View.VISIBLE);
loginButton.setVisibility(View.GONE);
AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken());
firebaseAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult> () {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(getApplicationContext(), R.string.firebase_error_login, Toast.LENGTH_LONG).show();
}
progressBar.setVisibility(View.GONE);
loginButton.setVisibility(View.VISIBLE);
}
});
}
private void goMainScreen() {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onStart() {
super.onStart();
firebaseAuth.addAuthStateListener(firebaseAuthListener);
}
@Override
protected void onStop() {
super.onStop();
firebaseAuth.removeAuthStateListener(firebaseAuthListener);
}
}
Arquivo Manifest:
<application
android:allowBackup="true"
android:icon="@mipmap/iconenovo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".Activity.Activity.Activity.MainLoginActivity"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<!-- Facebook Login-->
<meta-data
android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<!-- //Facebook Login-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="CHAVE CORRETA, EU APAGUEI AQUI" />
<!-- Chamando Activity ViewPager-->
<activity
android:name=".Activity.Activity.Activity.ViewPage"
android:label="@string/app_name"
android:theme="@style/FullScreen" />
<!-- //Chamando Activity ViewPager-->
<!-- Chamada da Activity principal- MainActivity -->
<activity
android:name=".Activity.Activity.Activity.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<!-- //Chamada da Activity principal- MainActivity -->