1

I am trying to do login with facebook in my app and want profile data. For that I want to generate key programatically but it gives me error. I done all other things as given here but all these things are not working for me and the code through which I want to generate key which gives me error.

I can do first login successfully (key generated by keytool command) but after that it showing invalid hash key error.

please help How can I get out from this.

The code which I pasted in MainApplication.java is

  @Override
  public void onCreate() {
  super.onCreate();
  AppEventsLogger.activateApp(this);


  try {
    PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(),PackageManager.GET_SIGNATURES);

  for (Signature signature : info.signatures) {
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.update(signature.toByteArray());
    Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
  }
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}

//SoLoader.init(this, /* native exopackage */ false);

}

and error showing on console is

  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:68: error: cannot find symbol
        PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackage
  Name(), PackageManager.GET_SIGNATURES);
        ^
    symbol:   class PackageInfo
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:68: error: cannot find symbol
        PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackage
  Name(), PackageManager.GET_SIGNATURES);

          ^
    symbol:   variable PackageManager
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:70: error: cannot find symbol
        for (Signature signature : info.signatures) {
             ^
    symbol:   class Signature
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:71: error: cannot find symbol
          MessageDigest md = MessageDigest.getInstance("SHA");
          ^
    symbol:   class MessageDigest
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:71: error: cannot find symbol
          MessageDigest md = MessageDigest.getInstance("SHA");
                             ^
    symbol:   variable MessageDigest
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:73: error: cannot find symbol
          Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                                                               ^
    symbol:   variable Base64
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:73: error: cannot find symbol
          Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                            ^
    symbol:   variable Base64
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:73: error: cannot find symbol
          Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
          ^
    symbol:   variable Log
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:75: error: cannot find symbol
      } catch (NameNotFoundException e) {
               ^
    symbol:   class NameNotFoundException
    location: class MainApplication
  C:\Users\saket\pro\pro20\android\app\src\main\java\com\pro20\MainApplication.jav
  a:77: error: cannot find symbol
      } catch (NoSuchAlgorithmException e) {
               ^
    symbol:   class NoSuchAlgorithmException
    location: class MainApplication
  10 errors
  :app:compileDebugJavaWithJavac FAILED

  FAILURE: Build failed with an exception.

  * What went wrong:
  Execution failed for task ':app:compileDebugJavaWithJavac'.
  > Compilation failed; see the compiler error output for details.

Where I am going wrong please help I am stuck on it.

Mayuresh Patil
  • 2,072
  • 1
  • 21
  • 44
  • you need to hardcoate the package name of your project and try.. – Abdul Wahab Jan 30 '18 at 19:29
  • Thanks for your reply, yes I did it already. my package name is `com.pro20` but also it is not working for me. What can i do now? Any package or any extra installation needs it for which i am unaware of. – Mayuresh Patil Jan 31 '18 at 15:06

1 Answers1

0

This problem is with openssl do not download latest version. If you have a 64 bit machine you must download openssl-0.9.8e X64 not the latest version.

then generate key using command

$ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

It will ask for password put "android" (not other)

Now it will work.

Mayuresh Patil
  • 2,072
  • 1
  • 21
  • 44