签名apk使用jsoup崩溃但调试没有

时间:2017-06-17 11:49:12

标签: android jsoup

可以解决我的问题吗? 我在游戏商店使用Jsoup进行版本检查。当我从android工作室运行我的应用程序作为调试apk。它运作良好。但是在生成签名Apk时。当运行此代码并显示消息时,它崩溃了#34;不幸的是应用已停止"。有谁帮助我。我告诉你我的代码。提前谢谢。

 private void getCurrentVersion(){
        try {
            currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        new GetLatestVersion().execute();
    }

public class GetLatestVersion extends AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... params) {
        try {
            latestVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + MainActivity.this.getPackageName() + "&hl=it")
                    .timeout(30000)
                    .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                    .referrer("http://www.google.com").get().select("div[itemprop=softwareVersion]").first().ownText();
            return latestVersion;
        }catch (Exception e){
            return latestVersion;
        }
    }

    @Override
    protected void onPostExecute(String version) {
        super.onPostExecute(version);
        if(version!=null) {
            if (!currentVersion.equals(latestVersion)){
                showUpdateDialog();
            }
        }
        else
            dialog.dismiss();

    }
    public boolean isFinished() {
        return true;
    }
}

private void showUpdateDialog(){
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("A New Update is Available");
    builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse
                    ("market://details?id=com.kjsdeveloper.sattagamblers")));
            dialog.dismiss();
        }
    });

    builder.setNegativeButton("Later", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.setCancelable(false);
    dialog = builder.show();
}

1 个答案:

答案 0 :(得分:2)

在位于Gradle Script的proguard-rules.pro文件中添加proguard规则 :

-keep public class org.jsoup.** {
    public *;
}