Search code examples
androidrecaptcha

How to implement reCAPTCHA Enterprise on android


I'm having trouble implementing reCAPTCHA Enterprise. Even adding in build.gradle implementation 'com.google.android.recaptcha:recaptcha:18.2.1'

When I implement the code, it does not recognize the recaptcha classes and cannot import

private void initializeRecaptchaClient() {
    Recaptcha
      .getTasksClient(getApplication(), "YOUR_SITE_KEY")
      .addOnSuccessListener(
          this,
          new OnSuccessListener<RecaptchaTasksClient>() {
            @Override
            public void onSuccess(RecaptchaTasksClient client) {
              MainActivity.this.recaptchaTasksClient = client;
            }
          })
      .addOnFailureListener(
          this,
          new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
              // Handle communication errors ...
              // See "Handle communication errors" section
            }
          });
  }

Solution

  • You can check class file in recaptcha package. If the files shows some problem about kotlin compiler abi version, you check your kotlin compiler abi version(File->Settings-> search kotlin) whether it is lower than needed. I should change kotlin compiler abi version, and then i find my android studio version is 3.5.3 and it is just support api version 1.3. If you want to support api version 1.8, you should download new android studio. You can find the correct android version from kotilin.