Dev Loots
Dev Loots

Reputation: 838

Could not find protoc-3.9.2-osx on Flutter/Android build

I am working on a Flutter application which integrates a native package which uses Protobuff. I work on Android Studio and Mac (Apple ship).

On windows, the application builds, but since I work on MacOs I can no longer build the application. I get the following error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ‘:mypackage:generateDebugProto’.
> Could not resolve all files for configuration ‘:mypackage:protobufToolsLocator_protoc’.
   > Could not find protoc-3.9.2-osx-aarch_64.exe (com.google.protobuf:protoc:3.9.2).
     Searched in the following locations:
         https://jcenter.bintray.com/com/google/protobuf/protoc/3.9.2/protoc-3.9.2-osx-aarch_64.exe

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 888ms
Exception: Gradle task assembleDebug failed with exit code 1

The build on iOS doesn't work either.

How can I resolve this error? Do you have any ideas on where the problem is coming from?

Upvotes: 3

Views: 11574

Answers (6)

Safargaleev Ruslan
Safargaleev Ruslan

Reputation: 301

os-maven-plugin update to version 1.7 helped me.

<extensions>
  <extension>
    <groupId>kr.motd.maven</groupId>
    <artifactId>os-maven-plugin</artifactId>
    <version>1.7.1</version>
   </extension>
 </extensions>

Upvotes: 0

Shubham Kumar Gupta
Shubham Kumar Gupta

Reputation: 1147

This is a simple check if you wanna work with and support both mac os with intel or m1 chip

protobuf {
        protoc {
            // a fix for m1
            artifact = if (osdetector.os == "osx") {
                "com.google.protobuf:protoc:3.20.0:osx-x86_64"
            } else {
                "com.google.protobuf:protoc:3.20.0"
            }
        }
        plugins {
            create("javalite") {
                artifact = if (osdetector.os == "osx") {
                    "com.google.protobuf:protoc-gen-javalite:3.0.0:osx-x86_64"
                } else {
                    "com.google.protobuf:protoc-gen-javalite:3.0.0"
                }
            }
        }
        generateProtoTasks {
            all().configureEach {
                builtins {
                    create("java") {
                        option("lite")
                    }
                    create("kotlin") {
                        option("lite")
                    }
                }
            }
        }
    }

Upvotes: 2

Dany Nest
Dany Nest

Reputation: 1

If you use Apple Silicon chips and faced such error:

* What went wrong:
Execution failed for task ':generateProto'.
> Could not resolve all files for configuration ':protobufToolsLocator_protoc'.
   > Could not find protoc-3.6.1-osx-aarch_64.exe (com.google.protobuf:protoc:3.6.1).
     Searched in the following locations:
         https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.6.1/protoc-3.6.1-osx-aarch_64.exe

Just add ":osx-x86_64" to the artifact at the end

Before:

protobuf {
  protoc {
    artifact = 'com.google.protobuf:protoc:3.6.1'
  }
}

After:

protobuf {
      protoc {
        artifact = 'com.google.protobuf:protoc:3.6.1:osx-x86_64'
      }
    }

Upvotes: 0

Jamil Hasnine Tamim
Jamil Hasnine Tamim

Reputation: 4448

It's working for me for MacOs- m1 pro chip:

I have create file : $HOME/.gradle/gradle.properties with :

protoc_platform=osx-x86_64

And add this in your build.gradle (app)

android {
    ......

    sourceSets {
        main {
            proto {
            }
        }
    }
    .......
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
        resolutionStrategy.force "com.android.support:support-annotations:$supportLibVersion"
    }
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.0.2:osx-x86_64"
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.1.2:osx-x86_64'
        }
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0:osx-x86_64"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
    generatedFilesBaseDir = "$projectDir/build/generated"
}

Upvotes: 1

Dev Loots
Dev Loots

Reputation: 838

I have found a solution based on : https://github.com/grpc/grpc-java/issues/7690

I have create file : $HOME/.gradle/gradle.properties with :

protoc_platform=osx-x86_64

My build.gradle :

protobuf {
// Configure the protoc executable
protoc {
    // for apple m1, add protoc_platform=osx-x86_64 in $HOME/.gradle/gradle.properties
    if (project.hasProperty('protoc_platform')) {
        artifact = "com.google.protobuf:protoc:3.9.2:${protoc_platform}"
    } else {
        artifact = "com.google.protobuf:protoc:3.9.2"
    }
}
plugins {
    javalite {
        // The codegen for lite comes as a separate artifact
        if (project.hasProperty('protoc_platform')) {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0:${protoc_platform}"
        } else {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
     }
    }
 }

Upvotes: 19

Sunbreak
Sunbreak

Reputation: 501

x86_64 works both on Intel and Apple chips

import org.apache.tools.ant.taskdefs.condition.Os

// Compatible with macOS on Apple Silicon
def archSuffix = Os.isFamily(Os.FAMILY_MAC) ? ':osx-x86_64' : ''

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.20.1$archSuffix"
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0$archSuffix"
        }
    }
}

Upvotes: 6

Related Questions