Приложение Cra sh с Minify true в Gradle Android - PullRequest
0 голосов
/ 22 апреля 2020

Я пытаюсь получить текущую дату и время от Google. со следующим кодом

private class LongOperation extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... params) {
                try {
                    HttpClient httpclient = new DefaultHttpClient();

                    //for Android 9
                    httpclient.getConnectionManager().getSchemeRegistry().register(
                            new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)
                    );
                    HttpResponse response = httpclient.execute(new HttpGet("https://google.com/"));
                    StatusLine statusLine = response.getStatusLine();

                    if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                        String currentDateTime = response.getFirstHeader("Date").toString().replace("Date: ", "");


                        SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zz");
                        //  String temp = "Thu Dec 17 15:37:43 GMT+05:30 2015";
                        try {
                            date = formatter.parse(currentDateTime);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        SimpleDateFormat sd = new SimpleDateFormat("dd/MM/yyyyHH:mm:ss");
                        GoogleDate = sd.format(date);
                        System.out.println("Google Date  :" + GoogleDate);

                    } else {
                        //Closes the connection.
                        response.getEntity().getContent().close();
                        throw new IOException(statusLine.getReasonPhrase());
                    }
                } catch (IOException e) {
                    Log.d("Response", e.getMessage());
                }
        return GoogleDate;

    }

    @Override
    protected void onPostExecute(String serverDate) {

            Toast.makeText(MainActivity.this, "Time is "+ serverDate, Toast.LENGTH_SHORT).show();
}
    }

Он отлично работает в сборке и выпуске отладки, но когда я установил значение minify в файле Gradle, приложение вылетает и показывает следующую ошибку.

2020-04-23 00:36:39.558 18528-18575/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
Process: com.developer.emten, PID: 18528
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:355)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
    at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:784)
 Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference (Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference)
    at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(Unknown Source:43)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(Unknown Source:10)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(Unknown Source:4)
    at org.apache.commons.logging.LogFactory.getLog(Unknown Source:4)
    at org.apache.http.impl.client.AbstractHttpClient.<init>(Unknown Source:7)
    at org.apache.http.impl.client.DefaultHttpClient.<init>(Unknown Source:1)
    at com.developer.emten.activities.MainActivity$b.doInBackground(SourceFile:1)
    at android.os.AsyncTask$2.call(AsyncTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246) 
    at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    at java.lang.Thread.run(Thread.java:784) 
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference
    at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(Unknown Source:400)
    at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(Unknown Source:126)
    at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(Unknown Source:6)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(Unknown Source:10) 
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(Unknown Source:4) 
    at org.apache.commons.logging.LogFactory.getLog(Unknown Source:4) 
    at org.apache.http.impl.client.AbstractHttpClient.<init>(Unknown Source:7) 
    at org.apache.http.impl.client.DefaultHttpClient.<init>(Unknown Source:1) 
    at com.abc.app.activities.MainActivity$b.doInBackground(SourceFile:1) 
    at android.os.AsyncTask$2.call(AsyncTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246) 
    at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    at java.lang.Thread.run(Thread.java:784) 

Пожалуйста, помогите мне. Кто-нибудь может сказать мне скрипт Proguard, который нужно добавить?

Я также приложил вывод сборки. enter image description here

Ваша добрая помощь будет высоко оценена.

1 Ответ

0 голосов
/ 22 апреля 2020

Добавьте эту строку в ваши правила proguard:

-keep class org.apache.** { *; }
...