Protoc problem with M1 chip

Problem

when trying to run the project this error appears:

Could not find protoc-gen-javalite-3.0.0-osx-aarch_64.exe (com.google.protobuf:protoc-gen-javalite:3.0.0).
Searched in the following locations:
https://jcenter.bintray.com/com/google/protobuf/protoc-gen-javalite/3.0.0/protoc-gen-javalite-3.0.0-osx-aarch_64.exe

Cause

this is because protoc doesn’t support m1 yet

Solution

1- Create file at: $HOME/.gradle/gradle.properties

with the following:

protoc_platform=osx-x86_64

2- Modify android build.gradle to:

protobuf {
// Configure the protoc executable
protoc {
    if (project.hasProperty('protoc_platform')) {
        artifact = "com.google.protobuf:protoc:3.11.2:${protoc_platform}"
    } else {
        artifact = "com.google.protobuf:protoc:3.11.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"
        }
    }
}

5 Comments

  1. Can you please provide the whole file of build.gradle because I receive below error message?

    * Where:
    Build file ‘/Users/developer/Desktop/workspace/woo_mdgretail_app/android/build.gradle’ line: 17

    * What went wrong:
    A problem occurred evaluating root project ‘android’.
    > Could not find method protobuf() for arguments [build_2zjcr3mmq2uab3zukcq0telyw$_run_closure1$_closure4@100f80b8] on object of type org.gradle.api.internal.initialization.DefaultScriptHandler.

    • group ‘de.mintware.barcode_scan’
      version ‘1.0-SNAPSHOT’

      buildscript {
      ext.kotlin_version = ‘1.3.61’
      ext.protobuf_version = ‘0.8.8’
      repositories {
      google()
      jcenter()
      }

      dependencies {
      classpath ‘com.android.tools.build:gradle:3.5.3’
      classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”
      classpath “com.google.protobuf:protobuf-gradle-plugin:$protobuf_version”
      }
      }

      rootProject.allprojects {
      repositories {
      google()
      jcenter()
      }
      }

      apply plugin: ‘com.android.library’
      apply plugin: ‘kotlin-android’
      apply plugin: ‘com.google.protobuf’

      android {
      compileSdkVersion 29

      sourceSets {
      main.java.srcDirs += ‘src/main/kotlin’
      main.proto.srcDirs += ‘../protos’
      }
      defaultConfig {
      minSdkVersion 18
      testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner”
      }
      lintOptions {
      disable ‘InvalidPackage’
      }
      }

      protobuf {
      // Configure the protoc executable
      protoc {
      // Download from repositories
      // 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.11.4:${protoc_platform}”
      }else{
      artifact = “com.google.protobuf:protoc:3.11.4”
      }
      }
      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”
      }
      }
      }
      generateProtoTasks {
      all().each { task ->
      task.plugins {
      javalite { }
      }
      }
      }
      }

      dependencies {
      implementation ‘androidx.appcompat:appcompat:1.1.0’
      implementation “org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version”
      implementation ‘me.dm7.barcodescanner:zxing:1.9.13’
      implementation ‘com.google.protobuf:protobuf-lite:3.0.1’
      api ‘com.google.android.material:material:1.1.0’
      }

      • This is my app/build.gradle
        ——————————————
        buildscript {
        repositories {
        // …
        maven { url ‘https://plugins.gradle.org/m2/’ } // Gradle Plugin Portal
        }
        dependencies {
        // …
        // OneSignal-Gradle-Plugin
        classpath ‘gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.9, 0.99.99]’
        }
        }

        def localProperties = new Properties()
        def localPropertiesFile = rootProject.file(‘local.properties’)
        if (localPropertiesFile.exists()) {
        localPropertiesFile.withReader(‘UTF-8’) { reader ->
        localProperties.load(reader)
        }
        }

        def flutterRoot = localProperties.getProperty(‘flutter.sdk’)
        if (flutterRoot == null) {
        throw new GradleException(“Flutter SDK not found. Define location with flutter.sdk in the local.properties file.”)
        }

        def flutterVersionCode = localProperties.getProperty(‘flutter.versionCode’)
        if (flutterVersionCode == null) {
        flutterVersionCode = ’33’
        }

        def flutterVersionName = localProperties.getProperty(‘flutter.versionName’)
        if (flutterVersionName == null) {
        flutterVersionName = ‘3.1.0’
        }
        apply plugin: ‘com.onesignal.androidsdk.onesignal-gradle-plugin’
        apply plugin: ‘com.android.application’
        apply plugin: ‘kotlin-android’
        apply plugin: ‘com.google.protobuf’
        apply plugin: ‘com.google.gms.google-services’
        apply from: “$flutterRoot/packages/flutter_tools/gradle/flutter.gradle”
        repositories{
        maven { url ‘https://maven.google.com’ }
        }
        def keystoreProperties = new Properties()
        def keystorePropertiesFile = rootProject.file(‘key.properties’)
        if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
        }

        android {
        compileSdkVersion 29

        sourceSets {
        main.java.srcDirs += ‘src/main/kotlin’
        main.proto.srcDirs += ‘../protos’
        }

        lintOptions {
        disable ‘InvalidPackage’
        // checkReleaseBuilds false
        }
        protobuf {
        // Configure the protoc executable
        protoc {
        // Download from repositories
        // 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.11.4:${protoc_platform}”
        }else{
        artifact = “com.google.protobuf:protoc:3.11.4”
        }
        }
        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”
        }
        }
        }
        generateProtoTasks {
        all().each { task ->
        task.plugins {
        javalite { }
        }
        }
        }
        }
        defaultConfig {
        applicationId “com.seventhcomputing.burmart”
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner”
        multiDexEnabled true
        resConfigs “en”
        manifestPlaceholders = [
        onesignal_app_id: ‘98575370-9e4c-4ac6-8c7d-9b32d04728b9’,
        // Project number pulled from dashboard, local value is ignored.
        onesignal_google_project_number: ‘REMOTE’
        ]
        }

        signingConfigs {
        release {

        if (System.getenv()[“CI”]) { // CI=true is exported by Codemagic
        storeFile file(System.getenv()[“FCI_BUILD_DIR”] + “/key.jks”)
        storePassword System.getenv()[“FCI_KEYSTORE_PASSWORD”]
        keyAlias System.getenv()[“FCI_KEY_ALIAS”]
        keyPassword System.getenv()[“FCI_KEY_PASSWORD”]
        } else {
        keyAlias keystoreProperties[‘keyAlias’]
        keyPassword keystoreProperties[‘keyPassword’]
        storeFile file(keystoreProperties[‘storeFile’])
        storePassword keystoreProperties[‘storePassword’]
        }
        }
        }

        buildTypes {
        release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run –release` works.
        signingConfig signingConfigs.release
        shrinkResources false
        minifyEnabled false
        proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’
        }
        debug {
        proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’
        }
        }
        }

        flutter {
        source ‘../..’
        }

        dependencies {
        implementation “org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version”
        implementation ‘com.android.support:multidex:1.0.3’
        implementation platform(‘com.google.firebase:firebase-bom:26.4.0’)
        implementation ‘com.google.firebase:firebase-analytics’
        implementation ‘com.onesignal:OneSignal:[3.15.4, 3.99.99]’
        implementation ‘com.anjlab.android.iab.v3:library:1.0.44’
        implementation ‘com.google.firebase:firebase-analytics:17.4.3’
        implementation ‘com.google.android.gms:play-services-base:17.3.0’
        implementation ‘me.dm7.barcodescanner:zxing:1.9.13’
        implementation ‘com.google.protobuf:protobuf-lite:3.0.1’
        }
        apply plugin: ‘com.google.gms.google-services’
        googleServices.disableVersionCheck = true

        this is android/build.gradle
        ——————————————
        buildscript {
        ext.kotlin_version = ‘1.3.50’
        ext.protobuf_version = ‘0.8.8’
        repositories {
        google()
        jcenter()
        maven { url ‘https://plugins.gradle.org/m2/’ }
        }

        dependencies {
        classpath ‘com.android.tools.build:gradle:4.1.0’
        classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”
        classpath ‘com.google.gms:google-services:4.3.3’
        classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”
        classpath “com.google.protobuf:protobuf-gradle-plugin:$protobuf_version”
        }
        }

        allprojects {
        repositories {
        google()
        mavenLocal()an
        jcenter()
        }
        }

        rootProject.buildDir = ‘../build’
        subprojects {
        project.buildDir = “${rootProject.buildDir}/${project.name}”
        }
        subprojects {
        project.evaluationDependsOn(‘:app’)
        afterEvaluate {project ->
        if (project.hasProperty(“android”) && project.property(“android”).compileSdkVersion.equals(“android-R”)) {
        android {
        compileSdkVersion 30
        }
        }
        }
        }

        task clean(type: Delete) {
        delete rootProject.buildDir
        }

        This is my two build.gradle file.I added exactly as your comments.But still getting below error.

        Execution failed for task ‘:barcode_scan:generateDebugProto’.
        > Could not resolve all files for configuration ‘:barcode_scan:protobufToolsLocator_javalite’.
        > Could not find protoc-gen-javalite-3.0.0-osx-aarch_64.exe (com.google.protobuf:protoc-gen-javalite:3.0.0).
        Searched in the following locations:
        https://jcenter.bintray.com/com/google/protobuf/protoc-gen-javalite/3.0.0/protoc-gen-javalite-3.0.0-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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Select your currency
USD United States (US) dollar