I am trying to release my app on Google Play. I have a Facebook login in my app. Up until yesterday all was working fine till the time I was running the application with
I have found a fantastic solution to manage debug and release environments.
1.Generate two hashes, for debug using this command:
keytool -exportcert -alias androiddebugkey -keystore c:\Users\YourUser\.android\debug.keystore | openssl sha1 -binary | openssl base64
And this one for release:
keytool -exportcert -alias "yourAliasUsedWhenYouGeneratedTheKey" -keystore "C:\Users\YourUser\AppData\Local\Android\android-studio\key.jks" | openssl sha1 -binary | openssl base64
2.Go to Facebook Applications and create TWO applications, one "Your Application" and other "Your Application (debug)". Then assign the debug hash to the debug application and the release hash to the normal application (obvious).
3.Get both Application Id and write them in the strings.xml file this way:
123456789
987654321
4.And finally, in your code, register the appId programatically in your Facebook Login fragment this way:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
String appId;
try {
ApplicationInfo appinfo = getActivity().getPackageManager().getApplicationInfo(getActivity().getPackageName(), 0);
boolean isDebugMode = (0 != (appinfo.flags &= ApplicationInfo.FLAG_DEBUGGABLE));
if (isDebugMode)
appId = getString(R.string.app_id_debug);
else
appId = getString(R.string.app_id);
} catch (PackageManager.NameNotFoundException e) {
appId = getString(R.string.app_id);
}
Session session = new Session.Builder(getActivity().getBaseContext()).setApplicationId(appId).build();
Session.setActiveSession(session);
return inflater.inflate(R.layout.fragment_facebook_login, container, false);
}
This way you will use the right appId and the right application on every environment without changing anything!!