Skip to content

Support Android projects #16

@alexander-yevsyukov

Description

@alexander-yevsyukov

Currently ProtoData fails if it's added to an Android project. The stacktrace is this:

...
Caused by: java.lang.IllegalStateException: sourceSet should not be used in an Android project
	at com.google.common.base.Preconditions.checkState(Preconditions.java:502)
	at com.google.protobuf.gradle.GenerateProtoTask.getSourceSet(GenerateProtoTask.groovy:301)
	at com.google.protobuf.gradle.GenerateProtoTask_Decorated.getSourceSet(Unknown Source)
	at io.spine.protodata.gradle.plugin.PluginKt$configureProtobufPlugin$1$2.invoke(Plugin.kt:206)
	at io.spine.protodata.gradle.plugin.PluginKt$configureProtobufPlugin$1$2.invoke(Plugin.kt:201)
	at org.gradle.kotlin.dsl.KotlinClosure1.doCall(GroovyInteroperability.kt:94)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:73)
	at org.gradle.util.ConfigureUtil.configureTarget(ConfigureUtil.java:203)
	at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:157)

This happens because of this code in the Gradle plugin (com.google.protobuf.gradle.GenerateProtoTask.groovy):

  @Internal("Inputs tracked in getSourceFiles()")
  SourceSet getSourceSet() {
    Preconditions.checkState(!isAndroidProject.get(),
        'sourceSet should not be used in an Android project')
    Preconditions.checkNotNull(sourceSet, 'sourceSet is not set')
    return sourceSet
  }

The first problem is that we use the internal API, which does not have a stability guarantee.
The second problem is we don't run under an Android project. I've stumbled on this issue when tried to create a test for checking that we don't add kotlin built-in for protoc if there's no Java or Kotlin enabled for a project.

The test is PluginTest.add 'kotlin' built-in only' if 'java' plugin or Kotlin compile tasks are present() and is currently disabled with the reference to this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions