10

I'm using this technique to make release builds ask for keystore passwords, but lately the Android Studio editor for build.gradle complains:

Cannot resolve symbol 'groovy'

for the line:

import groovy.swing.SwingBuilder

It didn't used to complain. The command line build ./gradlew assembleRelease still works. It's only AS that can't import groovy.

This is with Android Studio 2.3.1, Gradle 3.3, Android Gradle plugin 2.3.1.

Is there some AS configuration to make it happy?

Amazingly enough, the import error doesn't keep AS from making debug builds, and build.gradle doesn't try to use Swing in a debug build.

Community
  • 1
  • 1
Jerry101
  • 12,157
  • 5
  • 44
  • 63
  • I found at least three duplicate questions - please search before you ask! - https://stackoverflow.com/questions/39740238/i-cant-import-javax-swing - https://stackoverflow.com/questions/11895016/android-how-to-convert-java-swing-to-android - https://stackoverflow.com/questions/28544821/how-to-import-javax-swing-in-android-studio – jesses.co.tt May 29 '19 at 14:45
  • To clarify, this question is about running Swing at build time, in gradle, in Android Studio, on the cross-development machine, not in Android. – Jerry101 May 29 '19 at 17:00
  • AH, apologies. Not sure that I fully understand, but i'll take your word for it! – jesses.co.tt May 29 '19 at 17:18

2 Answers2

2

Starting with Gradle 6.x, gradle no longer embeds a copy of groovy-all, so groovy-swing is not included. https://docs.gradle.org/current/userguide/upgrading_version_6.html#groovy_modularization

This can be solved by adding e.g. org.codehaus.groovy:groovy-swing:3.0.9 to your buildscript in your top-level build.gradle file.

buildscript {
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath 'org.codehaus.groovy:groovy-swing:3.0.9'
    }
}
acoder
  • 126
  • 1
  • 5
0

Swing is an alternative Java library for creating UI, and this is in contravention to the Core Android APIs. As such, Swing is not supported on Android.

This page has the list of available Java packages (from Java 8, or whatever Version you put in your build.gradle...) https://developer.android.com/reference/packages.html

jesses.co.tt
  • 2,689
  • 1
  • 30
  • 49
  • 1
    Thanks, Jesses, but you misunderstood the question: This code runs in gradle within Android Studio on the cross-development machine, not in Android. And it succeeds in using Swing (to request the keystore passwords for a release build) but the AS editor still displays an error. That error is wrong although merely annoying once you find out that the build will work. – Jerry101 May 29 '19 at 16:54