Solution 1 :
I was able to fix my problem as follows:
- Uninstall all versions in my SDK for build-tools:
$ANDROID_HOME/tools/bin/sdkmanager --uninstall "build-tools;28.0.3"
$ANDROID_HOME/tools/bin/sdkmanager --uninstall "build-tools;29.0.2"
- I then installed build-tools;27.0.2
`$ANDROID_HOME/tools/bin/sdkmanager –install “build-tools;27.0.2”
- Then I just did my gradle build:
./gradlew clean assembleRelease
This automatically downloaded and installed build-tools;28.0.3 as my gradle projects specify it for targetSdkVersion and compileSdkVersion> And the build was successful!
I believe in all of above steps removal of the build-tools;29.0.2 was the most significant part. Is suspect that version of build-tools adds additional pesky checks to fail compilation.
NOTE: I had to switch to JDK 8 to run sdkmanager
Problem :
I have an android project that uses some hidden API (e plan to fix this in future but not now).
The same master branch of the project’s git repo builds fine is some build environments but gives compile errors in some build environment on the lines of code that use the hidden api.
The command I use in both environment is: ./gradlew clean assembleRelease
In one environment it builds fine. In another environment it gives compile errors like:
> Task :myproject:compileReleaseJavaWithJavac FAILED
/home/farrukh/myproject/src/main/java/com/mycompany/myproject/MyClass.java:4: error: cannot find symbol
import android.os.SystemProperties;
^
symbol: class SystemProperties
location: package android.os
/home/farrukh/myproject/src/main/java/com/mycompany/myproject/MyClass.java:82: error: cannot find symbol
partNumber = SystemProperties.get("ro.boot.partnumber", null);
^
symbol: variable SystemProperties
location: class MyClass
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
In both cases the Android SDK has Android 9.0 (API 28) installed but the specific sub-version could be different.
In the environment where the build fails the following info is generated from sdkmanager --list
:
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;28.0.3 | 28.0.3 | Android SDK Build-Tools 28.0.3 | build-tools/28.0.3/
build-tools;29.0.2 | 29.0.2 | Android SDK Build-Tools 29.0.2 | build-tools/29.0.2/
emulator | 30.0.0 | Android Emulator | emulator/
patcher;v4 | 1 | SDK Patch Applier v4 | patcher/v4/
platform-tools | 29.0.6 | Android SDK Platform-Tools | platform-tools/
platforms;android-18 | 3 | Android SDK Platform 18 | platforms/android-18/
platforms;android-23 | 3 | Android SDK Platform 23 | platforms/android-23/
platforms;android-24 | 2 | Android SDK Platform 24 | platforms/android-24/
platforms;android-26 | 2 | Android SDK Platform 26 | platforms/android-26/
platforms;android-27 | 3 | Android SDK Platform 27 | platforms/android-27/
platforms;android-28 | 6 | Android SDK Platform 28 | platforms/android-28/
platforms;android-29 | 4 | Android SDK Platform 29 | platforms/android-29/
sources;android-28 | 1 | Sources for Android 28 | sources/android-28/
sources;android-29 | 1 | Sources for Android 29 | sources/android-29/
tools | 26.1.1 | Android SDK Tools | tools/
The environment where it works is a Jenkins build wher sdkmanager --list
shows the following:
Installed packages:
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;27.0.1 | 27.0.1 | Android SDK Build-Tools 27.0.1 | build-tools/27.0.1/
build-tools;27.0.2 | 27.0.2 | Android SDK Build-Tools 27.0.2 | build-tools/27.0.2/
emulator | 29.0.11 | Android Emulator | emulator/
extras;android;m2repository | 47.0.0 | Android Support Repository | extras/android/m2repository/
extras;google;m2repository | 58 | Google Repository | extras/google/m2repository/
patcher;v4 | 1 | SDK Patch Applier v4 | patcher/v4/
platform-tools | 29.0.1 | Android SDK Platform-Tools | platform-tools/
tools | 26.1.1 | Android SDK Tools | tools/
Any idea what could cause the difference in build behavior?
Could the difference in Build Tools version (working env has 27.0.1, while not working env has 28.0.3) cause this difference?
UPDATE: Two very similar jenkins job built with same android SDK packages listed just above produce similar different result where one compiles the code fine and another fails to compile code using hidden apis. So the difference is not the SDK package versions. What else should I look for as difference between working and not working environment?