Support setting target_sdk_version separately from sdk_version
Before this change, if targetSdkVersion wasn't set in the AndroidManifest.xml, we'd set it to the sdk_version from the Android.bp. But there are cases where you want to compile against a later SDK, but target an earlier one (especially if you depend on libraries that need to be compiled against more recent SDKs, like androidx). Test: build APK with different target_sdk_version. Change-Id: Iaed36b522955a374a049ef331158cc8fc5798ad2
This commit is contained in:
parent
b259ede324
commit
419290aba9
|
@ -413,6 +413,10 @@ func (a *AARImport) minSdkVersion() string {
|
|||
return a.sdkVersion()
|
||||
}
|
||||
|
||||
func (a *AARImport) targetSdkVersion() string {
|
||||
return a.sdkVersion()
|
||||
}
|
||||
|
||||
var _ AndroidLibraryDependency = (*AARImport)(nil)
|
||||
|
||||
func (a *AARImport) ExportPackage() android.Path {
|
||||
|
|
|
@ -58,7 +58,7 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext
|
|||
Output: fixedManifest,
|
||||
Args: map[string]string{
|
||||
"minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
|
||||
"targetSdkVersion": sdkVersionOrDefault(ctx, sdkContext.sdkVersion()),
|
||||
"targetSdkVersion": sdkVersionOrDefault(ctx, sdkContext.targetSdkVersion()),
|
||||
"args": strings.Join(args, " "),
|
||||
},
|
||||
})
|
||||
|
|
|
@ -484,6 +484,10 @@ func (j *Javadoc) minSdkVersion() string {
|
|||
return j.sdkVersion()
|
||||
}
|
||||
|
||||
func (j *Javadoc) targetSdkVersion() string {
|
||||
return j.sdkVersion()
|
||||
}
|
||||
|
||||
func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
|
||||
if ctx.Device() {
|
||||
if !Bool(j.properties.No_standard_libs) {
|
||||
|
|
13
java/java.go
13
java/java.go
|
@ -183,6 +183,10 @@ type CompilerDeviceProperties struct {
|
|||
// Defaults to sdk_version if not set.
|
||||
Min_sdk_version *string
|
||||
|
||||
// if not blank, set the targetSdkVersion in the AndroidManifest.xml.
|
||||
// Defaults to sdk_version if not set.
|
||||
Target_sdk_version *string
|
||||
|
||||
// if true, compile against the platform APIs instead of an SDK.
|
||||
Platform_apis *bool
|
||||
|
||||
|
@ -425,11 +429,20 @@ func (j *Module) minSdkVersion() string {
|
|||
return j.sdkVersion()
|
||||
}
|
||||
|
||||
func (j *Module) targetSdkVersion() string {
|
||||
if j.deviceProperties.Target_sdk_version != nil {
|
||||
return *j.deviceProperties.Target_sdk_version
|
||||
}
|
||||
return j.sdkVersion()
|
||||
}
|
||||
|
||||
type sdkContext interface {
|
||||
// sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set.
|
||||
sdkVersion() string
|
||||
// minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set.
|
||||
minSdkVersion() string
|
||||
// targetSdkVersion returns the target_sdk_version property of the current module, or sdkVersion() if it is not set.
|
||||
targetSdkVersion() string
|
||||
}
|
||||
|
||||
func sdkVersionOrDefault(ctx android.BaseContext, v string) string {
|
||||
|
|
Loading…
Reference in New Issue