Bugly对应用进行升级

Bugly对应用进行升级

1使用Android Studio创建project

2配置示例(路径app/build.gradle):

android {
        defaultConfig {
          ndk {
            //设置支持的SO库架构
            abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
          }
        }
}
dependencies {
  //注释掉原有bugly的仓库
  //compile 'com.tencent.bugly:crashreport:latest.release'//其中latest.release指代最新版本号,也可以指定明确的版本号,例如2.3.2
  compile 'com.tencent.bugly:crashreport_upgrade:latest.release'//其中latest.release指代最新版本号,也可以指定明确的版本号,例如1.2.0
  compile 'com.tencent.bugly:nativecrashreport:latest.release' //其中latest.release指代最新版本号,也可以指定明确的版本号,例如2.2.0
}

3在AndroidMainfest.xml中进行以下配置:

1.权限配置

name="android.permission.READ_PHONE_STATE" />
name="android.permission.INTERNET" />
name="android.permission.ACCESS_NETWORK_STATE" />
name="android.permission.ACCESS_WIFI_STATE" />
name="android.permission.READ_LOGS" />
name="android.permission.WRITE_EXTERNAL_STORAGE" />

2.Activity配置

name="com.tencent.bugly.beta.ui.BetaActivity"
    android:configChanges="keyboardHidden|orientation|screenSize|locale"
    android:theme="@android:style/Theme.Translucent" />

4创建App.java

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        Beta.autoCheckUpgrade = false;//设置不自动检查
        Log.i("App","init success");
        Bugly.init(getApplicationContext(), "336b7711dc", false);
    }
}

5AndroidManifest.xml

allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:name=".App"
        android:theme="@style/AppTheme">

6MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv = (TextView) findViewById(R.id.tv);

        tv.setText("当前版本号versionName为: " + BuildConfig.VERSION_NAME);

        Button btn = (Button) findViewById(R.id.btn);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this,"checking",Toast.LENGTH_SHORT).show();
                Beta.checkUpgrade();//检查版本号
            }
        });
    }
}

7源码下载地址:

https://gitee.com/oschina_liang/myBuglyasd

你可能感兴趣的:(android)