Enforce newapi check only if min_sdk_version < compile_sdk_version

- NewApi check should be enforced only if min_sdk_version is less than
  the compile_sdk_version (the opposite direction should be a different
  build-time error)
- Change the datatype of *sdkVersion to android.ApiLevel (from string)
  to support version comparisons

Test: go build ./java
Test: no changes in ninja file
Bug: 228956345

Merged-In: Ic408857db7760d912ef4694d2ed72c0b7106eb04
Change-Id: Ic408857db7760d912ef4694d2ed72c0b7106eb04
(cherry picked from commit ba7e532a11)
This commit is contained in:
Spandan Das
2022-04-22 17:28:25 +00:00
parent 2b5384bc93
commit a3264efb42
2 changed files with 12 additions and 12 deletions

View File

@@ -1481,11 +1481,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
}
if ctx.Device() {
lintSDKVersionString := func(sdkSpec android.SdkSpec) string {
lintSDKVersion := func(sdkSpec android.SdkSpec) android.ApiLevel {
if v := sdkSpec.ApiLevel; !v.IsPreview() {
return v.String()
return v
} else {
return ctx.Config().DefaultAppTargetSdk(ctx).String()
return ctx.Config().DefaultAppTargetSdk(ctx)
}
}
@@ -1494,9 +1494,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.linter.srcJars = srcJars
j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
j.linter.classes = j.implementationJarFile
j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion(ctx))
j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion(ctx))
j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion(ctx))
j.linter.minSdkVersion = lintSDKVersion(j.MinSdkVersion(ctx))
j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx))
j.linter.compileSdkVersion = lintSDKVersion(j.SdkVersion(ctx))
j.linter.compileSdkKind = j.SdkVersion(ctx).Kind
j.linter.javaLanguageLevel = flags.javaVersion.String()
j.linter.kotlinLanguageLevel = "1.3"