react-native-voice / voice

:microphone: React Native Voice Recognition library for iOS and Android (Online and Offline Support)
MIT License
1.83k stars 495 forks source link

Expo Android: Could not find method compile() for arguments #467

Open waymond91 opened 11 months ago

waymond91 commented 11 months ago

Hello, I am using this on a very simple Expo app in a bare workflow. iOS compiles and works fine, however when I npx expo run:android or eas build --profile development --platform android I get the following error:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/brett/TableTalk/android/app/build.gradle' line: 178

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method compile() for arguments [project ':@react-native-voice_voice'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

I tried manually linking (but to be honest Im not very familiar with the process), some other people mentioned I needed to change the the node modules: https://stackoverflow.com/questions/23796404/could-not-find-method-compile-for-arguments-gradle

However, Im not really sure to what extent expo alters your iOS and android folders... I also tried install with yarn, npm, and expo install.

If I npx expo doctor I get:

Expected package @expo/config-plugins@~7.2.2
Found invalid:
  @expo/config-plugins@2.0.4
  (for more info, run: npm why @expo/config-plugins)
Advice: Upgrade dependencies that are using the invalid package versions.

Which seems to indicate react-native-expo is requiring an old version of @expo/config-plugins:

➜  TableTalk git:(main) ✗ npm list @expo/config-plugins
tabletalk@1.0.0 /Users/brett/TableTalk
├── @expo/config-plugins@7.2.5
├─┬ @react-native-voice/voice@3.2.4
│ └── @expo/config-plugins@2.0.4
├─┬ expo-constants@14.4.2
│ └─┬ @expo/config@8.1.2
│   └── @expo/config-plugins@7.2.5 deduped
├─┬ expo-splash-screen@0.20.5
│ └─┬ @expo/prebuild-config@6.2.6
│   └── @expo/config-plugins@7.2.5 deduped
├─┬ expo-updates@0.18.17
│ └── @expo/config-plugins@7.2.5 deduped
└─┬ expo@49.0.20
  ├─┬ @expo/cli@0.10.15
  │ └── @expo/config-plugins@7.2.5 deduped
  └── @expo/config-plugins@7.2.5 dedupe

Any help would be much appreciated! I was floored by how well this worked on iOS!

Just for good measure, my package.json is below:

{
  "name": "tabletalk",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@expo/config-plugins": "~7.2.2",
    "@react-native-voice/voice": "^3.2.4",
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.17",
    "@reduxjs/toolkit": "^1.9.7",
    "@rneui/base": "^4.0.0-rc.7",
    "@rneui/themed": "^4.0.0-rc.8",
    "axios": "^1.6.2",
    "expo": "~49.0.15",
    "expo-constants": "~14.4.2",
    "expo-dev-client": "~2.4.12",
    "expo-splash-screen": "~0.20.5",
    "expo-status-bar": "~1.6.0",
    "expo-updates": "~0.18.17",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-elements": "^3.4.3",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "~3.22.0",
    "react-native-vector-icons": "^10.0.2",
    "react-native-voice": "^0.3.0",
    "react-redux": "^8.1.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

And I got the following in my app.json:

"plugins": [
      [
        "@react-native-voice/voice",
        {
          "microphonePermission": "CUSTOM: Allow $(PRODUCT_NAME) to access the microphone",
          "speechRecognitionPermission": "CUSTOM: Allow $(PRODUCT_NAME) to securely recognize user speech"
        }
      ]
    ],
ndeso17 commented 11 months ago

eas.json :

{
  "cli": {
    "version": ">= 5.9.0"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "preview2": {
      "android": {
        "gradleCommand": ":app:assembleRelease"
      }
    },
    "production": {}
  },
  "submit": {
    "production": {}
  }
}

app.json :

{
  "expo": {
    "name": "LoginApp",
    "slug": "LoginApp",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": ["**/*", "./assets/fonts/*"],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "permissions": ["android.permission.RECORD_AUDIO"],
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "package": "com.pitikkuning.LoginApp"
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "extra": {
      "eas": {
        "projectId": "hbjqb3biuinrk2j84jjke"
      }
    },
    "plugins": [
      [
        "expo-av",
        {
          "microphonePermission": "Allow Voice to Text Tutorial to access the microphone",
          "speechRecognitionPermission": "Allow Voice to Text Tutorial to securely recognize user speech"
        }
      ],
      [
        "@react-native-voice/voice",
        {
          "microphonePermission": "Allow Voice to Text Tutorial to access the microphone",
          "speechRecognitionPermission": "Allow Voice to Text Tutorial to securely recognize user speech"
        }
      ]
    ]
  }
}

package.json :

{
  "name": "loginapp",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@expo/config-plugins": "~7.2.2",
    "@react-native-picker/picker": "2.4.10",
    "@rneui/base": "^4.0.0-rc.8",
    "@rneui/themed": "^4.0.0-rc.8",
    "expo": "^49.0.20",
    "expo-av": "~13.4.1",
    "expo-dev-client": "~2.4.12",
    "expo-file-system": "~15.4.5",
    "expo-font": "~11.4.0",
    "expo-permissions": "~14.2.1",
    "expo-speech": "~11.3.0",
    "expo-splash-screen": "^0.20.5",
    "expo-status-bar": "~1.6.0",
    "expo-system-ui": "~2.4.0",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-reanimated": "~3.3.0",
    "react-native-safe-area-context": "4.6.3",
    "react-native-vector-icons": "^10.0.2",
    "react-native-web": "^0.19.9",
    "twrnc": "^3.6.4"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@react-native-voice/voice": "^3.2.4",
    "customize-cra": "^1.0.0",
    "react-app-rewired": "^2.2.1"
  },
  "private": true
}

with the eas.json app.json and package.json configurations as above, I was able to successfully build the application. But when I run the application I don't get the output value from the speech listening process.

useEffect(() => {
    Voice.onSpeechError = (error) => setErrorListening(error.error);
    Voice.onSpeechResults = (result) => setResultListening(result.value[0]);
    Voice.onSpeechStart = () => setListeningSpeech(true);
    Voice.onSpeechEnd = () => setListeningSpeech(false);
    return () => {
      Voice.destroy().then(Voice.removeAllListeners);
    };
  }, []);

const startListening = async () => {
    try {
      await Voice.start("en-US");
      setListeningSpeech(true);
    } catch (error) {
      setErrorListening(error);
    }
  };
  const stopListening = async () => {
    try {
      await Voice.stop();
      setListeningSpeech(false);
    } catch (error) {
      setErrorListening(error);
    }
  };
rzfzr commented 11 months ago

Has this been solved? The main issue might be the fact that the linking instructions are outdated? The link command has been deprecated.

waymond91 commented 11 months ago

I have not got it to work yet, but its been a few days since Ive been able to try. using expo install instead of yarn may have helped.

anhtukhtn commented 1 month ago

'compile project' has been deprecated, using 'implementation' instead of 'compile'