Skip to content

[pigeon] Result interface is declared multiple times causing build errors #72240

Closed
flutter/packages
#328

Description

@MatrixDev

Bug

Steps to Reproduce

  1. Create pigeons/bridge.dart file.
  2. Add multiple HostApi classes with methods that return value (type can be different):
import 'package:pigeon/pigeon.dart';

class Response {
  int result;
}

@HostApi()
abstract class BridgeApi1 {
  @async
  Response call();
}

@HostApi()
abstract class BridgeApi2 {
  @async
  Response call();
}
  1. Generate pigeon files:
flutter pub run pigeon \
  --input pigeons/bridge.dart \
  --dart_out lib/pigeons/Bridge.dart \
  --java_out android/app/src/main/kotlin/com/pigeons/Bridge.java \
  --java_package "com.my.pigeons"
  1. Try to compile Android code

Expected results:

Code compiles.

Actual results:

Error is thrown:
error: interface Result is already defined in class Bridge

Versions

pigeon: 0.1.17

Generated Bridge.java

// Autogenerated from Pigeon (v0.1.17), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.my.pigeons;

import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import java.util.ArrayList;
import java.util.HashMap;

/** Generated class from Pigeon. */
@SuppressWarnings("unused")
public class Bridge {

  /** Generated class from Pigeon that represents data sent in messages. */
  public static class Response {
    private Long result;
    public Long getResult() { return result; }
    public void setResult(Long setterArg) { this.result = setterArg; }

    HashMap toMap() {
      HashMap<String, Object> toMapResult = new HashMap<>();
      toMapResult.put("result", result);
      return toMapResult;
    }
    static Response fromMap(HashMap map) {
      Response fromMapResult = new Response();
      Object result = map.get("result");
      fromMapResult.result = (result == null) ? null : ((result instanceof Integer) ? (Integer)result : (Long)result);
      return fromMapResult;
    }
  }

  public interface Result<T> {
    void success(T result);
  }

  /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
  public interface BridgeApi1 {
    void call(Result<Response> result);

    /** Sets up an instance of `BridgeApi1` to handle messages through the `binaryMessenger` */
    static void setup(BinaryMessenger binaryMessenger, BridgeApi1 api) {
      {
        BasicMessageChannel<Object> channel =
            new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.BridgeApi1.call", new StandardMessageCodec());
        if (api != null) {
          channel.setMessageHandler((message, reply) -> {
            HashMap<String, HashMap> wrapped = new HashMap<>();
            try {
              api.call(result -> { wrapped.put("result", result.toMap()); reply.reply(wrapped); });
            }
            catch (Exception exception) {
              wrapped.put("error", wrapError(exception));
              reply.reply(wrapped);
            }
          });
        } else {
          channel.setMessageHandler(null);
        }
      }
    }
  }

  public interface Result<T> {
    void success(T result);
  }

  /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
  public interface BridgeApi2 {
    void call(Result<Response> result);

    /** Sets up an instance of `BridgeApi2` to handle messages through the `binaryMessenger` */
    static void setup(BinaryMessenger binaryMessenger, BridgeApi2 api) {
      {
        BasicMessageChannel<Object> channel =
            new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.BridgeApi2.call", new StandardMessageCodec());
        if (api != null) {
          channel.setMessageHandler((message, reply) -> {
            HashMap<String, HashMap> wrapped = new HashMap<>();
            try {
              api.call(result -> { wrapped.put("result", result.toMap()); reply.reply(wrapped); });
            }
            catch (Exception exception) {
              wrapped.put("error", wrapError(exception));
              reply.reply(wrapped);
            }
          });
        } else {
          channel.setMessageHandler(null);
        }
      }
    }
  }
  private static HashMap wrapError(Exception exception) {
    HashMap<String, Object> errorMap = new HashMap<>();
    errorMap.put("message", exception.toString());
    errorMap.put("code", exception.getClass().getSimpleName());
    errorMap.put("details", null);
    return errorMap;
  }
}

Activity

  1. iapicca commented on Dec 13, 2020

    @iapicca

    as requested in pigeon feedback cc @gaaclarke

  2. pedromassangocode commented on Dec 14, 2020

    @pedromassangocode

    Reproducible with the latest version of the package.

    Important to notice that the issue is only reproducible with the @async annotation!

    Pigeon template
    import 'package:pigeon/pigeon.dart';
    
    class PlatformVersionMessage {
      String string;
    }
    
    @HostApi()
    abstract class PlatformVersionApi {
      @async
      PlatformVersionMessage getPlatformVersion();
    }
    
    @HostApi()
    abstract class PlatformVersionApi2 {
      @async
      PlatformVersionMessage getPlatformVersion();
    }
    
    Pigeon Java result
    // Autogenerated from Pigeon (v0.1.16), do not edit directly.
    // See also: https://pub.dev/packages/pigeon
    
    package com.nevercode.triage;
    
    import io.flutter.plugin.common.BasicMessageChannel;
    import io.flutter.plugin.common.BinaryMessenger;
    import io.flutter.plugin.common.StandardMessageCodec;
    import java.util.ArrayList;
    import java.util.HashMap;
    
    /** Generated class from Pigeon. */
    @SuppressWarnings("unused")
    public class Pigeons {
    
      /** Generated class from Pigeon that represents data sent in messages. */
      public static class PlatformVersionMessage {
        private String string;
        public String getString() { return string; }
        public void setString(String setterArg) { this.string = setterArg; }
    
        HashMap toMap() {
          HashMap<String, Object> toMapResult = new HashMap<>();
          toMapResult.put("string", string);
          return toMapResult;
        }
        static PlatformVersionMessage fromMap(HashMap map) {
          PlatformVersionMessage fromMapResult = new PlatformVersionMessage();
          Object string = map.get("string");
          fromMapResult.string = (String)string;
          return fromMapResult;
        }
      }
    
      public interface Result<T> {
        void success(T result);
      }
    
      /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
      public interface PlatformVersionApi2 {
        void getPlatformVersion(Result<PlatformVersionMessage> result);
    
        /** Sets up an instance of `PlatformVersionApi2` to handle messages through the `binaryMessenger` */
        static void setup(BinaryMessenger binaryMessenger, PlatformVersionApi2 api) {
          {
            BasicMessageChannel<Object> channel =
                new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.PlatformVersionApi2.getPlatformVersion", new StandardMessageCodec());
            if (api != null) {
              channel.setMessageHandler((message, reply) -> {
                HashMap<String, HashMap> wrapped = new HashMap<>();
                try {
                  api.getPlatformVersion(result -> { wrapped.put("result", result.toMap()); reply.reply(wrapped); });
                }
                catch (Exception exception) {
                  wrapped.put("error", wrapError(exception));
                  reply.reply(wrapped);
                }
              });
            } else {
              channel.setMessageHandler(null);
            }
          }
        }
      }
    
      public interface Result<T> {
        void success(T result);
      }
    
      /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
      public interface PlatformVersionApi {
        void getPlatformVersion(Result<PlatformVersionMessage> result);
    
        /** Sets up an instance of `PlatformVersionApi` to handle messages through the `binaryMessenger` */
        static void setup(BinaryMessenger binaryMessenger, PlatformVersionApi api) {
          {
            BasicMessageChannel<Object> channel =
                new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.PlatformVersionApi.getPlatformVersion", new StandardMessageCodec());
            if (api != null) {
              channel.setMessageHandler((message, reply) -> {
                HashMap<String, HashMap> wrapped = new HashMap<>();
                try {
                  api.getPlatformVersion(result -> { wrapped.put("result", result.toMap()); reply.reply(wrapped); });
                }
                catch (Exception exception) {
                  wrapped.put("error", wrapError(exception));
                  reply.reply(wrapped);
                }
              });
            } else {
              channel.setMessageHandler(null);
            }
          }
        }
      }
      private static HashMap wrapError(Exception exception) {
        HashMap<String, Object> errorMap = new HashMap<>();
        errorMap.put("message", exception.toString());
        errorMap.put("code", exception.getClass().getSimpleName());
        errorMap.put("details", null);
        return errorMap;
      }
    }
  3. github-actions commented on Aug 2, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions