TeamCity InteliliJ-based Inspections on Android Gradle Project Follow
No matter what we try, we cannot get our IntelliJ-based inspections to run correctly on TeamCity because it can never find the Android SDK. I've tried many different possibilities for getting the IntelliJ running to find it on startup, but no matter what I try, it can't find it. This, of course, causes many inspection failures. On each new TeamCity release, I try it again and troubleshoot again, but even he problem always exhibits as a slightly different error message in the logs, the end result is still the same. I've tried everything from many variations of ANDROID_HOME configuration to manually setting other environment variables I've suspected of affecting it to manually creating a local.properties file before each run. No luck. The details of our inspections config and the message from the log is below. Anyone have any advice on how to further troubleshoot?
TEAMCITY 10.0 INSPECTIONS CONFIG
Runner Type: Inspections (IntelliJ IDEA)
Project File Type: Gradle
Path to Project: build.gradle
JDK: JDK 1.8 x66
JVM Command Line Parameters: -Xmx1g
All other config values are defaults.
ERROR IN TEAMCITY 10.0
[16:10:20]Step 4/4: Inspect (Inspections (IntelliJ IDEA)) (2m:28s)
[16:10:20]Starting: /charter/jdk18/bin/java -Dagent.home.dir=/charter/TeamCity/buildAgent2 -Dagent.name=Agent #2 -Dagent.ownPort=9091 -Dagent.work.dir=/charter/TeamCity/buildAgent2/work -Dbuild.number=Build 6519 -Dbuild.vcs.number=25d110c007dd2dabdc03979e39c3862fbf74a2fe -Dbuild.vcs.number.1=25d110c007dd2dabdc03979e39c3862fbf74a2fe -Dbuild.vcs.number.TechMobile_TechViewClient_TechViewClient=25d110c007dd2dabdc03979e39c3862fbf74a2fe -Dglobal.library.WebLogic.18.104.22.168.0.path=/charter/WebLogic12c -Dglobal.library.WebLogic.22.214.171.124.0.path=/charter/WebLogic126.96.36.199 -Didea.build.agent.port=9091 -Didea.config.path=/charter/TeamCity/buildAgent2/temp/buildTmp/config -Didea.home.path=/charter/TeamCity/buildAgent2/tools/idea -Didea.jars.nocopy=true -Didea.no.jdk.check=true -Didea.plugins.path=/charter/TeamCity/buildAgent2/tools/idea/plugins -Didea.system.path=/charter/TeamCity/buildAgent2/system/.intellij_idea/90e8880cdac8b139/90e8880cdac8b139/system_build.gradle -Djava.awt.headless=true -Djava.io.tmpdir=/charter/TeamCity/buildAgent2/temp/buildTmp -Djava.library.path=/charter/TeamCity/buildAgent2/tools/idea/bin -Dnewlocalvcs.disabled=true -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Dpath.macro.MAVEN.REPOSITORY=/charter/.m2/repository -Dteamcity.agent.cpuBenchmark=531 -Dteamcity.agent.dotnet.agent_url=http://localhost:9091/RPC2 -Dteamcity.agent.dotnet.build_id=15608 -Dteamcity.auth.password=1daM3tvs9pgM0O1plg9VxwIk1kCXDxac -Dteamcity.auth.userId=TeamCityBuildId=15608 -Dteamcity.build.changedFiles.file=/charter/TeamCity/buildAgent2/temp/buildTmp/changedFiles6880166224350499308.txt -Dteamcity.build.checkoutDir=/charter/TeamCity/buildAgent2/work/90e8880cdac8b139 -Dteamcity.build.id=15608 -Dteamcity.build.properties.file=/charter/TeamCity/buildAgent2/temp/buildTmp/teamcity.build7142490231382307241.properties -Dteamcity.build.tempDir=/charter/TeamCity/buildAgent2/temp/buildTmp -Dteamcity.build.workingDir=/charter/TeamCity/buildAgent2/work/90e8880cdac8b139 -Dteamcity.buildConfName=Build and Inspect TechView Client -Dteamcity.buildType.id=TechMobile_TechViewClient_BuildAndInspectTechViewClient -Dteamcity.configuration.properties.file=/charter/TeamCity/buildAgent2/temp/buildTmp/teamcity.config8451399120605605900.properties -Dteamcity.projectName=TechView Client -Dteamcity.runner.properties.file=/charter/TeamCity/buildAgent2/temp/buildTmp/teamcity.runner6356834898281352006.properties -Dteamcity.tests.recentlyFailedTests.file=/charter/TeamCity/buildAgent2/temp/buildTmp/testsToRunFirst8031102970618787900.txt -Dteamcity.version=10.0 (build 42002) -Xmx1g -Xbootclasspath/p:/charter/TeamCity/buildAgent2/tools/idea/lib/boot.jar -classpath /charter/jdk18/lib/tools.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/bootstrap.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/extensions.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/openapi.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/util.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/jdom.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/log4j.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/trove4j.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/jna.jar:/charter/TeamCity/buildAgent2/tools/idea/lib/slf4j-log4j12-1.7.10.jar com.intellij.idea.Main inspect /charter/TeamCity/buildAgent2/work/90e8880cdac8b139/build.gradle project /charter/TeamCity/buildAgent2/temp/buildTmp/inspection4892922516158795851result -e -v3
[16:10:20]in directory: /charter/TeamCity/buildAgent2/work/90e8880cdac8b139
[16:10:25]Starting up IntelliJ IDEA 2016.2 (build IU-162.1121.32) ...done.
[16:10:25][ 4248] WARN - .intellij.diagnostic.VMOptions - VM options file path missing
[16:11:13][ 51687] WARN - oid.AndroidSdkModuleCustomizer - Path to Android SDK not set
[16:11:13][ 51687] WARN - oid.AndroidSdkModuleCustomizer - # of eligible SDKs: 0
[16:11:13][ 51972] ERROR - .AndroidGradleModelDataService - Failed to set up Android modules in project 'AndroidClient'
[16:11:13]java.lang.IllegalArgumentException: Argument for @NotNull parameter 'sdk' of org/jetbrains/android/sdk/AndroidSdkData.getSdkData must not be null
[16:11:13] at org.jetbrains.android.sdk.AndroidSdkData.getSdkData(AndroidSdkData.java)
[16:11:13] at com.android.tools.idea.gradle.customizer.android.DependenciesModuleCustomizer.addExtraSdkLibrariesAsDependencies(DependenciesModuleCustomizer.java:159)
[16:11:13] at com.android.tools.idea.gradle.customizer.android.DependenciesModuleCustomizer.setUpDependencies(DependenciesModuleCustomizer.java:77)
Please sign in to leave a comment.
Hi Kyle, John,
Sorry for late answer, I've tried to reproduce problem but found another one in IDEA runner (not related to you problem though).
Have you tried to set 'env.ANDROID_HOME' configuration parameter?
Without it I've problem but with another stacktrace, with 'env.ANDROID_HOME' defined, it works fine.
Also you could run inspections using Android Studio:
* Download Android Studio zip for linux (or mac, any zip archive);
* Rename archive to something like 'android-studio.zip';
* Place archive into <TC_Data_Directory>/plugins/.tools/, it would be automatically distributed to all agents;
* Add 'system.idea.app.home=%teamcity.tool.generic.android-studio%' parameter to build configuration. On TeamCity 10.0.1 and newer remove `generic.`, though you would see proper variant in autocompletion.
Spent some time digging through the Android source code surrounding this problem. It appears from the AndroidSdkModuleCustomizer source code that it's only looking at IDE-configured SDKs to try and deduce the Android home directory, so then my question is, why isn't it also looking at the "ANDROID_HOME" environment variable or the "local.properties" file? In a TeamCity environment, there are no IDE-configured Android SDKs for IntelliJ-based inspections of Android Gradle projects, so how is this even passing internal testing? Does anyone actually use this feature? We're a half-step away from switching wholesale over to FindBugs or some other alternative instead.
Has a solution been found for this issue?
I experimented with this a bit more just today. Setting env.ANDROID_HOME has no effect. I have created a small sample project which demonstrates the issue on (at least) both Linux and MacOS. Inspections in this project run fine within Android Studio and fail on TeamCity. Since there doesn't seem to be a way to attach files to this forum, just send me an email to the email address associated with my profile and I will send it to you along with all the project configuration info I have setup to demonstrate the bug.
Just realized that you want me to try running inspections under TeamCity using Android Studio. Should have read more closely. I'm attempting that now.
Attempting to use Android Studio for the inspections just results in this error.
Error: Could not find or load main class com.intellij.idea.Main
Edit: Disregard. Realized my mistake. Trying again now.
Still getting this error -> "Error: Could not find or load main class com.intellij.idea.Main".
Attempted the same use of the android-studio.zip on Linux with the Linux zip download and also got the same error. My guess is something has changed in the zip layout to make it incompatible for use with the system.idea.app.home.
And I figured out that error. The .zip downloads of Android Studio contain a top-level directory which has to be removed and the .zip repackaged so that TeamCity can find everything it needs.
After repackaging the Linux and Mac distributions, I was able to get Android Studio working as the system.idea.app.home setting. However, after all that, it turns out the Android Studio behavior is identical to the IntelliJ IDEA behavior. Both methods are failing to find the Android SDK.