Android: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Asked Answered
T

3

9

I am trying to build my project on GitLab CI but unfortunately for me I keep getting this error inside the runner:

Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

Now I know there is something wrong with my environment but I just cant get my mind wrapped around the problem. I searched on the web and I found I needed to update my .gitignore file and I did here it is:

### Java ###
*.class

### Android ###
*.apk
*.ap_

### Package files ###
*.war
*.ear
*.aar

### Gradle ###
.gradle
 build
bin/
build/
build.xml
gen/
.gradle/
gradlew
gradlew.bat
gradle-wrapper.jar
gradle-wrapper.properties

### Android Studio ###
.idea
local.properties
.DS_Store
/captures

I also eddied my gradle.build to contain the following lines:

task wrapper(type: Wrapper) {
gradleVersion = '2.0' 
}

But again every time I run a build I get stack! Here is also my .gitlab-ci.yml:

before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip openjdk-7-jdk lib32stdc++6   lib32z1
 - wget --quiet --output-document=gradle.zip https://services.gradle.org/distributions/gradle-2.8-bin.zip
 - unzip -q gradle.zip
 - export ANDROID_HOME="/opt/android-sdk"
 - chmod +x gradlew

 dev:
 script:
 - ./gradlew assembleDebug

And the line where the error appears is:

- wget --quiet --output-document=gradle.zip https://services.gradle.org/distributions/gradle-2.8-bin.zip
Tumefy answered 10/5, 2016 at 8:21 Comment(0)
W
8

According to your gitignor, CI is never getting the gradle-wrapper.jar library, because it wasn't commited yet, but it has to be, since it is used to run the wrapper.

Check, whether is gradle-wrapper.jar commited, if no, then just commit it.

Wheresoever answered 10/5, 2016 at 9:6 Comment(0)
B
2

I got this error by trying to run:

./gradlew releaseTarGz
Could not find or load main class org.gradle.wrapper.GradleWrapperMain

My mistake was I didn't read or follow the directions: I had to run these two commands first to initialize things:

gradle
./gradlew jar

Then the ./gradlew releaseTarGz can find that main class as expected.

Bearce answered 8/7, 2016 at 14:45 Comment(0)
T
1

@Stanislav you were partly right. I managed to figure out the problem and of course as expected it was right in front of my eyes. So as we all know the runner/s on GitLab CI are all "empty". Meaning they don't have anything installed on them. That is why we have the .gitlab-ci.yml. Now looking back at my .gitlab-ci.yml I am telling the runner to get jdk7 & gradle but I am missing the Android SDK that is why the error appeared:

Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

So my new .gitlab-ci.yml looks like this and it compiles as it should:

before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip openjdk-7-jdk lib32stdc++6   lib32z1
- wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
- tar --extract --gzip --file=android-sdk.tgz
- echo y | android-sdk-linux/tools/android --silent update sdk -a -u -t 1,2,3,4,5,6,29,31,32,33,34,45,138,142,145,146,147,148,149,150,151
- wget --quiet --output-document=gradle.zip https://services.gradle.org/distributions/gradle-2.12-bin.zip
- unzip -q gradle.zip
- export ANDROID_HOME=$PWD/android-sdk-linux

build:
script:
- gradle-2.12/bin/gradle assembleDebug
artifacts:
paths:
- app/build/outputs/apk/app-release-unsigned.apk
Tumefy answered 11/5, 2016 at 6:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.