Skip to content

Commit 8d89668

Browse files
committed
优化buildconfig的获取
1 parent 0c54d2a commit 8d89668

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ android {
44
compileSdkVersion 32
55
buildToolsVersion "30.0.3"
66
defaultConfig {
7-
applicationId "com.vector.appupdatedemo"
7+
applicationId "com.vector.appupdatedemo2"
88
minSdkVersion 19
99
targetSdkVersion 32
1010
versionCode 1

sample/src/main/AndroidManifest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
</intent-filter>
3131
</activity>
3232

33-
<activity android:name=".ui.KotlinActivity">
34-
</activity>
3533
<activity android:name=".ui.JavaActivity">
3634
</activity>
3735

update-pyger/src/main/java/com/hss01248/update_pyger/PygerAppUpdateUtil.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,35 @@ public void onException(Exception e) {
3737
*/
3838
public static void doUpdate(@Nullable String apiKey,@Nullable String appKey, ExceptionHandler handler){
3939
if(TextUtils.isEmpty(apiKey) || TextUtils.isEmpty(appKey)){
40+
Class reflect = null;
41+
try {
42+
reflect = Class.forName(AppUtils.getAppPackageName() + ".BuildConfig");
4043

44+
} catch (ClassNotFoundException e) {
45+
LogUtils.i(e);
46+
String path = Utils.getApp().getClass().getName();
47+
LogUtils.i("application class path: "+path);
48+
path = path.substring(0,path.lastIndexOf("."));
49+
try {
50+
reflect = Class.forName(path + ".BuildConfig");
51+
} catch (ClassNotFoundException ex) {
52+
LogUtils.w(ex);
53+
}
54+
}
55+
if(reflect == null){
56+
LogUtils.w("没有找到BuildConfig,拿不到蒲公英的key,无法发起更新请求");
57+
return;
58+
}
4159
try {
42-
Class reflect = Class.forName(AppUtils.getAppPackageName() + ".BuildConfig");
43-
apiKey = (String) reflect.getDeclaredField("pyger_api_key").get(reflect);
60+
apiKey = (String) reflect.getDeclaredField("pyger_api_key").get(reflect);
4461
appKey = (String) reflect.getDeclaredField("pyger_app_key").get(reflect);
4562
LogUtils.i("get api_key and app_key : "+ apiKey+"->"+appKey);
46-
} catch (Exception e) {
47-
LogUtils.w(e);
63+
} catch (Throwable e) {
64+
LogUtils.i("app更新->没有配置相关key",e);
65+
//return;
4866
}
67+
68+
4969
}
5070
//FileDownloader.setup(Utils.getApp());
5171
//UpdateAppManager.setDefaultHttpImpl(new UpdateAppPgyer());

0 commit comments

Comments
 (0)