Skip to content

Commit

Permalink
Prefer decimal integer for platformBuildVersionName
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Mar 2, 2024
1 parent ba507c5 commit 8708b57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/reandroid/app/AndroidManifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.reandroid.utils.ObjectsUtil;

@SuppressWarnings("unused")
public interface AndroidManifest {

String getPackageName();
Expand All @@ -27,8 +28,8 @@ public interface AndroidManifest {
void setVersionName(String name);
Integer getPlatformBuildVersionCode();
void setPlatformBuildVersionCode(int version);
String getPlatformBuildVersionName();
void setPlatformBuildVersionName(String name);
Object getPlatformBuildVersionName();
void setPlatformBuildVersionName(Object name);

Integer getCompileSdkVersion();
void setCompileSdkVersion(int version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Iterator;
import java.util.List;

@SuppressWarnings("unused")
public class AndroidManifestBlock extends ResXmlDocument implements AndroidManifest {
private int mGuessedPackageId;
public AndroidManifestBlock(){
Expand Down Expand Up @@ -408,7 +409,7 @@ public void setPlatformBuildVersionCode(int version){
setManifestAttributeInt(NAME_platformBuildVersionCode, 0, version);
}
@Override
public String getPlatformBuildVersionName(){
public Object getPlatformBuildVersionName(){
ResXmlElement manifest = getManifestElement();
if(manifest == null){
return null;
Expand All @@ -417,11 +418,27 @@ public String getPlatformBuildVersionName(){
if(attribute == null ){
return null;
}
return attribute.getValueAsString();
if(attribute.getValueType() == ValueType.STRING){
return attribute.getValueAsString();
}
return attribute.getData();
}
@Override
public void setPlatformBuildVersionName(String name){
setManifestAttributeString(NAME_platformBuildVersionName, 0, name);
public void setPlatformBuildVersionName(Object name){
Integer versionNumber = null;
if(name instanceof Integer){
versionNumber = (Integer) name;
}else {
try{
versionNumber = Integer.parseInt((String) name);
}catch (NumberFormatException ignored){
}
}
if(versionNumber != null){
setManifestAttributeInt(NAME_platformBuildVersionName, 0, versionNumber);
}else{
setManifestAttributeString(NAME_platformBuildVersionName, 0, (String) name);
}
}
@Override
public Integer getMinSdkVersion(){
Expand Down

0 comments on commit 8708b57

Please sign in to comment.