'Braintree Integration - Error: Class not found: com.braintreepayments.api.dropin.DropInRequest

so we are currently trying to integrate Braintree in our Android App in Sandbox Environment. We have set up a server with WAMP, which is generating a client token. That is working. However, when we are trying to start the payment the following error message appears in logcat:

"E/Parcel: Class not found when unmarshalling: com.braintreepayments.api.dropin.DropInRequest java.lang.ClassNotFoundException: com.braintreepayments.api.dropin.DropInRequest"

The app does not perfom any actions. The error is weird, as we added the dependencies to the gradle file and the intent filter to the manifest. I will attach a screenshot of the error message, the complete code and the PHP code to this request.

We don't know what to do. Please help. Thank you.

Gradle File:

implementation 'com.braintreepayments.api:drop-in:3.7.1'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'junit:junit:4.12'
implementation 'com.android.support:multidex:1.0.1'

Manifest:

 <activity android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"
        android:launchMode="singleTask">
        <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="${applicationId}.braintree" />
        </intent-filter>
    </activity>

Relevant Code

essenBesätigenBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            submitPayment();
     }
});

private void submitPayment() {
    DropInRequest dropInRequest = new DropInRequest()
            .clientToken(clientToken);
    startActivityForResult(dropInRequest.getIntent(this), BRAINTREE_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode == BRAINTREE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
            PaymentMethodNonce nonce = result.getPaymentMethodNonce();
            String strNonce = nonce.getNonce();

            if (anzahlPortionen.getText().toString().isEmpty()) {
                anzahlPortionen.setError("Bitte gib eine Anzahl an Portionen an");
            } else if (preisRechner.getText().toString().equals("0€")) {
                Toast.makeText(EssenActivity.this, "Bitte berechne den Gesamtpreis vorher", Toast.LENGTH_SHORT).show();
            } else if (ungefähreAnkunft.getText().toString().equals("Wann ist deine ungefähre Ankunft?")) {
                ungefähreAnkunft.requestFocus();
                ungefähreAnkunft.setError("Bite gib deine ungefähre Ankunft an");
            } else
                irwas = preisRechner.getText().toString();
            amountB = irwas.replace("€", "");
            paramsHash = new HashMap<>();
            paramsHash.put("amount", amountB);
            paramsHash.put("nonce", strNonce);

            sendPayments();
            {
            }
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(EssenActivity.this, "Benutzer hat abgebrochen", Toast.LENGTH_SHORT).show();
        } else {
            Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
            Toast.makeText(EssenActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
        }

    }
}

private void sendPayments() {
    RequestQueue queue = Volley.newRequestQueue(EssenActivity.this);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, API_CHECK_OUT,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    if (response.toString().contains("Successfull")) {
                        Toast.makeText(EssenActivity.this, "Bezahlung war erfolgreich",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(EssenActivity.this, "Bezahlung war nicht erfolgreich",
                                Toast.LENGTH_SHORT).show();
                    }
                    Log.d(TAG, "onErrorResponse: " + response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "onErrorResponse: " + error.toString());
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            if (paramsHash == null)
                return null;
            Map<String,String> params = new HashMap<>();
            for (String key: params.keySet())
            {
                params.put(key, paramsHash.get(key));
            }
            return params;
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("Content-Type", "application/x-www-form-urlencoded");
            return params;
        }
    };
    queue.add(stringRequest);
}

private class getToken extends AsyncTask {


    //VLLT HIER?
    ProgressDialog mDialog;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        mDialog = new ProgressDialog(EssenActivity.this, android.R.style.Theme_DeviceDefault_Dialog);
        mDialog.setCancelable(false);
        mDialog.setMessage("Bitte warten");
        mDialog.show();
    }

    @Override
    protected Object doInBackground(Object[] objects) {
        HttpClient client = new HttpClient();
        client.get(API_GET_TOKEN, new HttpResponseCallback() {
            @Override
            public void success(final String responseBody) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        token = responseBody;
                    }
                });
            }

            @Override
            public void failure(Exception exception) {
                Toast.makeText(EssenActivity.this, exception.toString(), Toast.LENGTH_SHORT).show();
            }
        });
        return null;
    }

    @Override
    protected void onPostExecute(Object o) {
        super.onPostExecute(o);
        mDialog.dismiss();
    }
}


Solution 1:[1]

This works for me, try to remove this one implementation "com.braintreepayments.api:braintree:$braintree_version"

This is the solution i gained from

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Park Bo Young