1
I’m developing an app with Android Studio version 3.0 Canary, but I’m going through a boring problem.
Got like Activity initial with login through the Facebook. I’ve managed the key release to validate the login.
Error occurs when Gero one apk
on-mode debug, the application normally opens on Activity login, but when I compile a apk
in the way release, gives the error below and then closes automatically.:
O aplicativo parou
I saw that in some cell phones apk
release opens and others do not. My phone is Moto G version 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);
}
}
Manifest File:
<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 -->
I even tried to add the second permission. I didn’t. But internet access I had already put in. Here are the permissions I have used:
– Lucas Costa
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="com.google.android.apps.maps.permission.PREFETCH" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
– Lucas Costa