버전 표시 오류 수정
This commit is contained in:
@@ -1,20 +1,6 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
// 버전 정보를 properties 파일에서 동적으로 로드
|
||||
def versionPropsFile = rootProject.file('version.properties')
|
||||
def versionProps = new Properties()
|
||||
if (versionPropsFile.exists()) {
|
||||
versionPropsFile.withInputStream { stream -> versionProps.load(stream) }
|
||||
}
|
||||
|
||||
def versionName = versionProps['versionName'] ?: "1.1.1.2"
|
||||
def versionCode = (versionProps['versionCode'] ?: "6").toInteger()
|
||||
def buildNumber = (versionProps['buildNumber'] ?: "6").toInteger()
|
||||
|
||||
// 버전 정보 로깅
|
||||
println "버전 정보 로드: versionName=${versionName}, versionCode=${versionCode}, buildNumber=${buildNumber}"
|
||||
|
||||
// 버전 정보를 직접 설정
|
||||
android {
|
||||
namespace "com.lovable.zellyfinance"
|
||||
compileSdk rootProject.ext.compileSdkVersion
|
||||
@@ -22,10 +8,48 @@ android {
|
||||
applicationId "com.lovable.zellyfinance"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode = versionCode
|
||||
versionName = versionName
|
||||
// 빌드 번호 추가 - BuildConfig 필드로 정의
|
||||
buildConfigField("int", "BUILD_NUMBER", String.valueOf(buildNumber))
|
||||
|
||||
// version.properties 파일 로드
|
||||
def versionPropsFile = file("${rootDir}/version.properties")
|
||||
def versionProps = new Properties()
|
||||
|
||||
try {
|
||||
if (versionPropsFile.canRead()) {
|
||||
versionProps.load(new FileInputStream(versionPropsFile))
|
||||
println "버전 정보 로드: versionName=${versionProps['versionName']}, versionCode=${versionProps['versionCode']}, buildNumber=${versionProps['buildNumber']}"
|
||||
} else {
|
||||
println "version.properties 파일을 읽을 수 없음, 기본값 사용"
|
||||
versionProps['versionName'] = '1.1.1.2'
|
||||
versionProps['versionCode'] = '6'
|
||||
versionProps['buildNumber'] = '6'
|
||||
}
|
||||
} catch (Exception e) {
|
||||
println "버전 정보 로드 오류, 기본값 사용: ${e.message}"
|
||||
versionProps['versionName'] = '1.1.1.2'
|
||||
versionProps['versionCode'] = '6'
|
||||
versionProps['buildNumber'] = '6'
|
||||
}
|
||||
|
||||
// 빈 문자열이나 null 값 검사
|
||||
if (!versionProps['versionName'] || versionProps['versionName'].trim().isEmpty()) {
|
||||
versionProps['versionName'] = '1.1.1.2'
|
||||
}
|
||||
if (!versionProps['versionCode'] || versionProps['versionCode'].trim().isEmpty()) {
|
||||
versionProps['versionCode'] = '6'
|
||||
}
|
||||
if (!versionProps['buildNumber'] || versionProps['buildNumber'].trim().isEmpty()) {
|
||||
versionProps['buildNumber'] = '6'
|
||||
}
|
||||
|
||||
// 빌드 정보 설정
|
||||
versionName versionProps['versionName']
|
||||
versionCode versionProps['versionCode'] ? versionProps['versionCode'].toInteger() : 6
|
||||
|
||||
// 빌드 설정에 BuildConfig 필드 추가
|
||||
buildConfigField "String", "VERSION_NAME", "\"${versionProps['versionName']}\""
|
||||
buildConfigField "int", "VERSION_CODE", "${versionProps['versionCode'] ? versionProps['versionCode'].toInteger() : 6}"
|
||||
buildConfigField "int", "BUILD_NUMBER", "${versionProps['buildNumber'] ? versionProps['buildNumber'].toInteger() : 6}"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||
|
||||
@@ -21,33 +21,91 @@ public class BuildInfoPlugin extends Plugin {
|
||||
*/
|
||||
@PluginMethod
|
||||
public void getBuildInfo(PluginCall call) {
|
||||
// 오류가 발생하더라도 앱이 강제종료되지 않도록 전체 try-catch 블록 사용
|
||||
try {
|
||||
Log.d(TAG, "빌드 정보 요청 수신됨");
|
||||
|
||||
JSObject ret = new JSObject();
|
||||
String versionName = "";
|
||||
int versionCode = 0;
|
||||
int buildNumber = 0;
|
||||
|
||||
// BuildConfig에서 동적으로 버전 정보 가져오기
|
||||
String versionName = BuildConfig.VERSION_NAME;
|
||||
int versionCode = BuildConfig.VERSION_CODE;
|
||||
int buildNumber;
|
||||
|
||||
// 빌드 넘버는 커스텀 필드이므로 try-catch로 확인
|
||||
// 모든 필드 접근에 각각 try-catch 적용하여 실패하더라도 기본값 사용
|
||||
try {
|
||||
buildNumber = BuildConfig.BUILD_NUMBER;
|
||||
Log.d(TAG, "BuildConfig.BUILD_NUMBER: " + buildNumber);
|
||||
// Class.forName으로 BuildConfig 클래스 안전하게 접근
|
||||
Class<?> buildConfigClass = null;
|
||||
try {
|
||||
buildConfigClass = Class.forName("com.lovable.zellyfinance.BuildConfig");
|
||||
Log.d(TAG, "BuildConfig 클래스 로드 성공");
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.e(TAG, "BuildConfig 클래스를 찾을 수 없음", e);
|
||||
}
|
||||
|
||||
if (buildConfigClass != null) {
|
||||
// VERSION_NAME 필드 접근
|
||||
try {
|
||||
Object versionNameObj = buildConfigClass.getField("VERSION_NAME").get(null);
|
||||
if (versionNameObj != null) {
|
||||
versionName = versionNameObj.toString();
|
||||
Log.d(TAG, "VERSION_NAME 로드 성공: " + versionName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "VERSION_NAME 필드 접근 오류", e);
|
||||
}
|
||||
|
||||
// VERSION_CODE 필드 접근
|
||||
try {
|
||||
Object versionCodeObj = buildConfigClass.getField("VERSION_CODE").get(null);
|
||||
if (versionCodeObj != null) {
|
||||
versionCode = Integer.parseInt(versionCodeObj.toString());
|
||||
Log.d(TAG, "VERSION_CODE 로드 성공: " + versionCode);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "VERSION_CODE 필드 접근 오류", e);
|
||||
}
|
||||
|
||||
// BUILD_NUMBER 필드 접근
|
||||
try {
|
||||
Object buildNumberObj = buildConfigClass.getField("BUILD_NUMBER").get(null);
|
||||
if (buildNumberObj != null) {
|
||||
buildNumber = Integer.parseInt(buildNumberObj.toString());
|
||||
Log.d(TAG, "BUILD_NUMBER 로드 성공: " + buildNumber);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "BUILD_NUMBER 필드 접근 오류, 버전 코드로 대체", e);
|
||||
// 빌드 넘버 필드가 없으면 버전 코드와 동일하게 설정
|
||||
buildNumber = versionCode;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "BUILD_NUMBER 필드 접근 오류, 기본값 사용", e);
|
||||
buildNumber = versionCode; // 빌드 넘버가 없으면 버전 코드와 동일하게 설정
|
||||
Log.e(TAG, "BuildConfig 접근 중 예기치 않은 오류", e);
|
||||
}
|
||||
|
||||
// 버전 정보가 유효하지 않을 경우 version.properties 파일의 값이
|
||||
// 빌드 과정에서 이미 BuildConfig에 적용되었을 것이므로 별도의 하드코딩 없음
|
||||
if (versionName == null || versionName.isEmpty()) {
|
||||
Log.w(TAG, "버전명이 비어있음, BuildConfig에서 값을 가져오지 못함");
|
||||
}
|
||||
if (versionCode <= 0) {
|
||||
Log.w(TAG, "버전 코드가 유효하지 않음, BuildConfig에서 값을 가져오지 못함");
|
||||
}
|
||||
if (buildNumber <= 0) {
|
||||
Log.w(TAG, "빌드 번호가 유효하지 않음, BuildConfig에서 값을 가져오지 못함");
|
||||
}
|
||||
|
||||
// 디버깅을 위한 로그 출력
|
||||
Log.d(TAG, "BuildConfig 클래스: " + BuildConfig.class.getName());
|
||||
Log.d(TAG, "버전명: " + versionName);
|
||||
Log.d(TAG, "버전 코드: " + versionCode);
|
||||
Log.d(TAG, "빌드 번호: " + buildNumber);
|
||||
Log.d(TAG, "최종 버전명: " + versionName);
|
||||
Log.d(TAG, "최종 버전 코드: " + versionCode);
|
||||
Log.d(TAG, "최종 빌드 번호: " + buildNumber);
|
||||
|
||||
String packageName = getContext().getPackageName();
|
||||
Log.d(TAG, "패키지명: " + packageName);
|
||||
String packageName = "";
|
||||
try {
|
||||
packageName = getContext().getPackageName();
|
||||
Log.d(TAG, "패키지명: " + packageName);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "패키지명 가져오기 오류", e);
|
||||
packageName = "com.lovable.zellyfinance";
|
||||
}
|
||||
|
||||
// 결과 객체에 값 설정
|
||||
ret.put("versionName", versionName);
|
||||
@@ -67,20 +125,23 @@ public class BuildInfoPlugin extends Plugin {
|
||||
// 오류 로깅 강화
|
||||
Log.e(TAG, "빌드 정보 가져오기 오류", e);
|
||||
|
||||
// 오류 발생 시에도 기본 정보 반환하여 앱 중단 방지
|
||||
// 오류 발생 시에도 정보 반환하여 앱 중단 방지
|
||||
// build.gradle에서 설정한 기본값이 BuildConfig에 이미 적용되었을 것이므로
|
||||
// 별도의 하드코딩 없이 기본적인 정보만 포함
|
||||
JSObject fallbackResult = new JSObject();
|
||||
fallbackResult.put("versionName", "1.1.1.2"); // 버전명 기본값
|
||||
fallbackResult.put("versionCode", 6); // 버전 코드 기본값
|
||||
fallbackResult.put("buildNumber", 6); // 빌드 번호 기본값
|
||||
fallbackResult.put("packageName", getContext().getPackageName());
|
||||
fallbackResult.put("androidVersion", Build.VERSION.RELEASE);
|
||||
fallbackResult.put("androidSDK", Build.VERSION.SDK_INT);
|
||||
fallbackResult.put("platform", "android-fallback");
|
||||
fallbackResult.put("error", e.getMessage());
|
||||
fallbackResult.put("timestamp", System.currentTimeMillis());
|
||||
fallbackResult.put("androidVersion", Build.VERSION.RELEASE);
|
||||
fallbackResult.put("androidSDK", Build.VERSION.SDK_INT);
|
||||
|
||||
Log.d(TAG, "오류 발생으로 기본값 반환: " + fallbackResult.toString());
|
||||
call.resolve(fallbackResult); // reject 대신 기본값으로 resolve
|
||||
try {
|
||||
fallbackResult.put("packageName", getContext().getPackageName());
|
||||
} catch (Exception ex) {
|
||||
fallbackResult.put("packageName", "com.lovable.zellyfinance");
|
||||
}
|
||||
|
||||
// 응답 해결
|
||||
call.resolve(fallbackResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
buildNumber=6
|
||||
versionCode=6
|
||||
versionName=1.1.1.2
|
||||
buildNumber=7
|
||||
versionCode=7
|
||||
versionName=1.1.1.3
|
||||
|
||||
Reference in New Issue
Block a user