应用程序停止工作与签名的APK playstore版本,但从Android Studio编译的一个工作



当我登录时间表页面时,从android studio下载的版本下载到我的手机上,它工作正常,并带我到时间表。然而,当我尝试从playstore下载的版本登录时间表页面时,它只是永远加载。

那么我是否可以通过查看控制台的消息来测试从playstore下载的版本?(https://play.google.com/store/apps/details?id=com.gmail.gogobebe2.thedayahead)

完整的源代码:https://github.com/gogobebe2/TheDayAhead

这是它停止和从未登录的地方-登录按钮onclick listener:(https://github.com/gogobebe2/TheDayAhead/blob/master/app/src/main/java/com/gmail/gogobebe2/thedayahead/timetable/TimetableFragment.java#L192):

    @SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"})
    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.login_button) {
            if (kmarDocument == null) initKmarLoginConnection();
            else {
                EditText usernameEditText = (EditText) loginRelativeLayout.findViewById(R.id.editText_username);
                EditText passwordEditText = (EditText) loginRelativeLayout.findViewById(R.id.editText_password);
                updateLoginPreferences((CheckBox) loginRelativeLayout.findViewById(R.id.checkBox_rememberMe),
                        usernameEditText, passwordEditText);
                WebView webView = new WebView(getContext());
                webView.setVisibility(View.INVISIBLE);
                webView.clearCache(true);
                webView.clearHistory();
                clearCookies(this);
                webView.addJavascriptInterface(new HTMLRetrieverJavaScriptInterface(this), "HtmlRetriever");
                webView.setWebViewClient(new WebViewClient() {
                    @Override
                    public void onLoadResource(WebView webView, String destinationUrl) {
                        CheckBox rememberMeCheckbox = (CheckBox) loginRelativeLayout.findViewById(R.id.checkBox_rememberMe);
                        ProgressBar progressBar = (ProgressBar) loginRelativeLayout.findViewById(R.id.progressBar);
                        progressBar.setVisibility(View.VISIBLE);
                        rememberMeCheckbox.setVisibility(View.INVISIBLE);
                        super.onLoadResource(webView, destinationUrl);
                    }
                    @Override
                    public void onPageFinished(WebView webView, String urlLoaded) {
                        final String LOGIN_JAVASCRIPT = "javascript:document.getElementById("loginSubmit").click()";
                        final String HTML_RETRIEVER_JAVASCRIPT = "javascript:window.HtmlRetriever.showHTML" +
                                "('<html>' + document.getElementsByTagName('html')[0].innerHTML + '</html>');";
                        if (urlLoaded.equals(KMAR_TIMETABLE_URL)) {
                            // debug: webView.setVisibility(View.VISIBLE);
                            webView.loadUrl(HTML_RETRIEVER_JAVASCRIPT);
                        } else if (!urlLoaded.equals(LOGIN_JAVASCRIPT)) {
                            webView.loadUrl(LOGIN_JAVASCRIPT);
                        }
                    }
                });
                WebSettings webSettings = webView.getSettings();
                webSettings.setJavaScriptEnabled(true);
                loginRelativeLayout.addView(webView);
                Element loginUsernameElement = kmarDocument.getElementById("loginUsername");
                Element loginPasswordElement = kmarDocument.getElementById("loginPassword");
                loginUsernameElement.attr("value", usernameEditText.getText().toString());
                loginPasswordElement.attr("value", passwordEditText.getText().toString());
                webView.loadData(kmarDocument.html(), "text/html", "UTF-8");
                // I then call the click() function on the loginSubmit button when the page is finished
                // loading in the overridden onPageFinished(WebView webView, String url) method.
            }
        }
}

这是proguard文件。我不知道我这样做是否正确,但我在其他类似的堆栈溢出问题上看到过,问题通常是这样的。(https://github.com/gogobebe2/TheDayAhead/blob/master/app/proguard-rules.pro):

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/william/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class com.gmail.gogobebe2.thedayahead.timetable.TimetableFragment$HTMLRetrieverJavaScriptInterface {
   public *;
}

下面是javascript接口(https://github.com/gogobebe2/TheDayAhead/blob/master/app/src/main/java/com/gmail/gogobebe2/thedayahead/timetable/TimetableFragment.java#L177):

public class HTMLRetrieverJavaScriptInterface {
        TimetableFragment timetableFragment;
        HTMLRetrieverJavaScriptInterface(TimetableFragment timetableFragment) {
            super();
            this.timetableFragment = timetableFragment;
        }
        @JavascriptInterface
        void showHTML(String html) {
            kmarTimetableHTML = html;
            MainActivity.timetable = new Timetable(kmarTimetableHTML, timetableFragment);
        }
}
编辑:

build.gradle中,我将minifyEnabledfalse改为true。现在,使用从play store下载的应用程序,当我导航到时间表页面时,应用程序完全崩溃了。但是,如果我使用我从android studio下载的那个,它工作得很好。

自己解决了。

新的Javascript接口类:

    @Keep
    public class HTMLRetrieverJavaScriptInterface {
        TimetableFragment timetableFragment;
        public HTMLRetrieverJavaScriptInterface(TimetableFragment timetableFragment) {
            super();
            this.timetableFragment = timetableFragment;
        }
        @Keep
        @JavascriptInterface
        public void showHTML(String html) {
            kmarTimetableHTML = html;
            MainActivity.timetable = new Timetable(kmarTimetableHTML, timetableFragment);
        }
}

新建pro-guard文件:

-keepclassmembers class com.gmail.gogobebe2.thedayahead.timetable.TimetableFragment$HTMLRetrieverJavaScriptInterface {
   public *;
}
-keepattributes JavascriptInterface

相关内容

  • 没有找到相关文章

最新更新