I've cloned a project on Github. It uses different plugins.
dependencies:
flutter:
sdk: flutter
cupertino_icons: 0.1.2
firebase_auth: 0.7.0
google_sign_in: 3.2.4
cloud_firestore: 0.8.2+3
image_picker: 0.4.12+1
shared_preferences: 0.4.3
firebase_storage: 1.0.4
cached_network_image: 0.7.0
intl: 0.15.7
There is blog post which advises keeping versions the same. My problem is the image_picker plugin. Looking around stackoverflow it recommends using version 0.4.12+1 if you don't want to migrate app to Android X. Here is my error
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java:8: error: package android.support.annotation does not exist
import android.support.annotation.VisibleForTesting;
^
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:15: error: package android.support.annotation does not exist
import android.support.annotation.VisibleForTesting;
^
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java:40: error: cannot find symbol
#VisibleForTesting
^
symbol: class VisibleForTesting
location: class ImagePickerPlugin
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:68: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY = 2342;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:69: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA = 2343;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:70: error: cannot find symbol
#VisibleForTesting static final int REQUEST_EXTERNAL_IMAGE_STORAGE_PERMISSION = 2344;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:71: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CAMERA_IMAGE_PERMISSION = 2345;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:72: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CODE_CHOOSE_VIDEO_FROM_GALLERY = 2352;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:73: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CODE_TAKE_VIDEO_WITH_CAMERA = 2353;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:74: error: cannot find symbol
#VisibleForTesting static final int REQUEST_EXTERNAL_VIDEO_STORAGE_PERMISSION = 2354;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:75: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CAMERA_VIDEO_PERMISSION = 2355;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:77: error: cannot find symbol
#VisibleForTesting final String fileProviderName;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:164: error: cannot find symbol
#VisibleForTesting
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
13 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':image_picker:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* 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.
BUILD FAILED in 2s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1
I'm wondering what might be causing the incompatibilities prevent my app from compiling?
You need to flow the documentation for AndroidX compatibility
The best option is migrate the app for androidX. Follow the steps in android-studio:
1) Remove all your dependencies of your pubspec file and run flutter packages get
2) Open only android module of your app in android-studio. You can do this with right click on your project root directory > flutter > Open android module in android studio
3) After open only android module in android-studio menu go to Refactor > MigrateToAndoridX...
4) Do the migration!
5) Close android module android-studio instance and go back to your flutter project
6) Insert all your dependencies in pubspec file and run flutter packages get
Use image_picker: ^0.6.6+1 and add AndroidManifest.xml following:
<uses-permission android:name="android.permission.INTERNET"/>
This way worked for me!
Related
flutter 2.10.0 build failed
and the log like this:
↳
** BUILD FAILED **
Xcode's output:
↳
Writing result bundle at path:
/var/folders/50/z6jgw_3s1cvcqkyx0wc4llnc0000gn/T/flutter_tools.B4L9K8/flutter_ios_build_temp_dirM0C4eg/temporary_xcresult_bundle
../flutter/.pub-cache/hosted/pub.dartlang.org/win32-2.3.11/lib/src/structs.g.dart:666:31: Error: Member not found: 'UnicodeChar'.
int get UnicodeChar => Char.UnicodeChar;
^^^^^^^^^^^
../flutter/.pub-cache/hosted/pub.dartlang.org/win32-2.3.11/lib/src/structs.g.dart:667:38: Error: Setter not found: 'UnicodeChar'.
set UnicodeChar(int value) => Char.UnicodeChar = value;
^^^^^^^^^^^
../flutter/.pub-cache/hosted/pub.dartlang.org/win32-2.3.11/lib/src/structs.g.dart:669:29: Error: Member not found: 'AsciiChar'.
int get AsciiChar => Char.AsciiChar;
^^^^^^^^^
../flutter/.pub-cache/hosted/pub.dartlang.org/win32-2.3.11/lib/src/structs.g.dart:670:36: Error: Setter not found: 'AsciiChar'.
set AsciiChar(int value) => Char.AsciiChar = value;
^^^^^^^^^
Failed to package /Users/kangkang/Documents/hezhot.
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in parallel
Result bundle written to path:
/var/folders/50/z6jgw_3s1cvcqkyx0wc4llnc0000gn/T/flutter_tools.B4L9K8/flutter_ios_build_temp_dirM0C4eg/temporary_xcresult_bundle
Could not build the application for the simulator.
Error launching application on iPhone 11.
why dose it happended in flutter 2.10.0 dart 2.16.0
and I found maybe relevant to this issue :
enter link description here
what can I actually do?
I am trying to add video calling feature to my app and I am using Agora for it. But when I do the build I get the following error:
Launching lib\main.dart on Android SDK built for x86 in debug mode...
D:\Downloads\flutter_windows_2.5.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\ma
in\java\com\baseflow\permissionhandler\PermissionManager.java:321: error: cannot find symbol
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
^
symbol: variable S
location: class VERSION_CODES
D:\Downloads\flutter_windows_2.5.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\ma
in\java\com\baseflow\permissionhandler\PermissionUtils.java:72: error: cannot find symbol
case Manifest.permission.BLUETOOTH_SCAN:
^
symbol: variable BLUETOOTH_SCAN
location: class permission
D:\Downloads\flutter_windows_2.5.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\ma
in\java\com\baseflow\permissionhandler\PermissionUtils.java:74: error: cannot find symbol
case Manifest.permission.BLUETOOTH_ADVERTISE:
^
symbol: variable BLUETOOTH_ADVERTISE
location: class permission
D:\Downloads\flutter_windows_2.5.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\ma
in\java\com\baseflow\permissionhandler\PermissionUtils.java:76: error: cannot find symbol
case Manifest.permission.BLUETOOTH_CONNECT:
^
symbol: variable BLUETOOTH_CONNECT
location: class permission
D:\Downloads\flutter_windows_2.5.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\ma
in\java\com\baseflow\permissionhandler\PermissionUtils.java:259: error: cannot find symbol
String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_SCAN);
^
symbol: variable BLUETOOTH_SCAN
location: class permission
D:\Downloads\flutter_windows_2.5.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\ma
in\java\com\baseflow\permissionhandler\PermissionUtils.java:270: error: cannot find symbol
String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_ADVERTISE);
^
symbol: variable BLUETOOTH_ADVERTISE
location: class permission
D:\Downloads\flutter_windows_2.5.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\ma
in\java\com\baseflow\permissionhandler\PermissionUtils.java:281: error: cannot find symbol
String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_CONNECT);
^
symbol: variable BLUETOOTH_CONNECT
location: class permission
D:\Downloads\flutter_windows_2.5.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\ma
in\java\com\baseflow\permissionhandler\PermissionUtils.java:370: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasPermissionInManifest(context, null, permission )) {
^
symbol: variable S
location: class VERSION_CODES
8 errors
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':permission_handler:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
This is my pubspec.yaml:
dependencies:
#videocall
agora_rtc_engine: ^4.0.7
permission_handler: null
This is AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- The Agora SDK requires Bluetooth permissions in case users are using Bluetooth devices.-->
<uses-permission android:name="android.permission.BLUETOOTH" />
This is app\build.gradle:
defaultConfig {
applicationId "**********"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
Flutter Version: 2.6.0-12.0.pre.381
Dart Version: 2.15.0
Gradle version : distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
In pubspec.yaml, I have these packages:
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
splashscreen: ^1.2.0
bottom_navy_bar:
cupertino_icons: ^1.0.2
image_picker: ^0.8.0+4
fluttertoast: ^8.0.7
shared_preferences: ^2.0.6
share: ^2.0.4
flutter_barcode_scanner: ^2.0.0-nullsafety.0
dropdown_search: ^1.0.0
syncfusion_flutter_pdfviewer:
ndialog: ^4.1.0
flutter_pdfview: ^1.0.4
http: ^0.13.3
dio: ^4.0.0
path_provider: ^2.0.3
downloads_path_provider_28: ^0.1.2
permission_handler: ^8.1.4+2
open_file: ^3.2.1
flutter_local_notifications: ^9.0.0
Same packages are working in another project.
Any suggestions on how to fix the problem. I think it is due to some error in build.graddle.
I have changed minSdkVersion and targetSdkVersion in build.gradle as follows:
minSdkVersion 23
targetSdkVersion 29
multiDexEnabled true
It is showing error while running the project:
Launching lib\main.dart on SM M205F in debug mode...
Running Gradle task 'assembleDebug'...
Note: C:\flutter\.pub-cache\hosted\pub.dartlang.org\downloads_path_provider_28-0.1.2\android\src\main\java\it\nplace\downloadspathprovider\DownloadsPathProviderPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.8.4+2\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:58: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
^
symbol: variable R
location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:59: error: cannot find symbol
status = Environment.isExternalStorageManager()
^
symbol: method isExternalStorageManager()
location: class Environment
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:254: error: cannot find symbol
if (permission == PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE && Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
^
symbol: variable R
location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:268: error: cannot find symbol
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && permission == PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE) {
^
symbol: variable R
location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:270: error: cannot find symbol
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
^
symbol: variable ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
location: class Settings
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:321: error: cannot find symbol
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
^
symbol: variable S
location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:349: error: cannot find symbol
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
^
symbol: variable R
location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:380: error: cannot find symbol
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
^
symbol: variable R
location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:384: error: cannot find symbol
return Environment.isExternalStorageManager()
^
symbol: method isExternalStorageManager()
location: class Environment
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:64: error: cannot find symbol
case Manifest.permission.MANAGE_EXTERNAL_STORAGE:
^
symbol: variable MANAGE_EXTERNAL_STORAGE
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:72: error: cannot find symbol
case Manifest.permission.BLUETOOTH_SCAN:
^
symbol: variable BLUETOOTH_SCAN
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:74: error: cannot find symbol
case Manifest.permission.BLUETOOTH_ADVERTISE:
^
symbol: variable BLUETOOTH_ADVERTISE
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:76: error: cannot find symbol
case Manifest.permission.BLUETOOTH_CONNECT:
^
symbol: variable BLUETOOTH_CONNECT
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:235: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && hasPermissionInManifest(context, permissionNames, Manifest.permission.MANAGE_EXTERNAL_STORAGE ))
^
symbol: variable R
location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:235: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && hasPermissionInManifest(context, permissionNames, Manifest.permission.MANAGE_EXTERNAL_STORAGE ))
^
symbol: variable MANAGE_EXTERNAL_STORAGE
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:236: error: cannot find symbol
permissionNames.add(Manifest.permission.MANAGE_EXTERNAL_STORAGE);
^
symbol: variable MANAGE_EXTERNAL_STORAGE
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:259: error: cannot find symbol
String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_SCAN);
^
symbol: variable BLUETOOTH_SCAN
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:270: error: cannot find symbol
String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_ADVERTISE);
^
symbol: variable BLUETOOTH_ADVERTISE
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:281: error: cannot find symbol
String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_CONNECT);
^
symbol: variable BLUETOOTH_CONNECT
location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:370: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasPermissionInManifest(context, null, permission )) {
^
symbol: variable S
location: class VERSION_CODES
20 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':permission_handler:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* 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 44s
Exception: Gradle task assembleDebug failed with exit code 1
This is happing due to compileSdkVersion. Head over to android/app/build.gradle and change complieSdkVersion to 31.
android {
compileSdkVersion 31
...
}
In pubspec.yaml file :-
dependencies:
permission_handler: ^8.2.5
The error must be happening in versions 8.2.0 and onwards. If you still encounter some error then install a version less 8.2.0.
Faced the same issue and this is how i solved it:
First i removed permission_handler from my yaml file.
Then did a flutter clean.
In pubspec.yaml : I changed the version of the permission_handler plugin from 8.2.6 to:
permission_handler: ^8.2.0
Then In android/app/build.grale file:changed compile sdk version to 31.
I think that Build.VERSION_CODES.R is API Level 30 , so setting compileSdkVersion to 30 should fix the issue .
I changed permission_handler: ^8.1.4+2 with permission_handler: 6.0.0 in pubspec.yaml .Now project is working fine. Thanks for your assistance.
I am using Eclipse with Gradle. Twilio is listed as dependency. All versions are up to date. Code referencing Gradle will not compile and returns error messages that the Twilio classes do not exist. Code online is frustratingly outdated. I'm hoping someone here can help.
The Code I am running is very basic:
package SendAndReceiveSms;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class SmsSender {
public static final String ACCOUNT_SID = "**Redacted**";
public static final String AUTH_TOKEN = "**Redacted**";
public static void main(String[] args) {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(
new PhoneNumber("**redacted**"),
new PhoneNumber("**redacted**"),
"Message testing.")
.create();
System.out.println(message.getSid());
//sendMessage("**redacted**");
}
public void sendMessage(String numToSend) {
String n = numToSend;
Message message = Message.creator(
new PhoneNumber(n),
new PhoneNumber("+**(redacted)**"),
"Message testing.")
.create();
System.out.println(message.getSid());
}
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.2-jre'
//compile group: "com.twilio.sdk", name: "twilio", version: "7.45.+"
//compile group: "com.sparkjava", name: "spark-core", version: "2.7.1"
//compile group: "org.slf4j", name: "slf4j-simple", version: "1.7.21"
implementation 'org.slf4j:slf4j-simple:1.7.+'
implementation 'com.sparkjava:spark-core:2.5.+'
implementation group: 'com.twilio.sdk', name: 'twilio', version: '8.11.0'
//implementation 'com.twilio.sdk:twilio:7.+'
// implementation 'com.twilio.sdk', name: 'twilio', version: '8.11.0'
//runtimeOnly group: 'com.twilio.sdk', name: 'twilio', version: '8.11.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
Error code in Terminal:
SmsSender.java:3: error: package com.twilio does not exist
import com.twilio.Twilio;
^
SmsSender.java:4: error: package com.twilio.rest.api.v2010.account does not exist
import com.twilio.rest.api.v2010.account.Message;
^
SmsSender.java:5: error: package com.twilio.type does not exist
import com.twilio.type.PhoneNumber;
^
SmsSender.java:12: error: cannot find symbol
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
^
symbol: variable Twilio
location: class SmsSender
SmsSender.java:13: error: cannot find symbol
Message message = Message.creator(
^
symbol: class Message
location: class SmsSender
SmsSender.java:14: error: cannot find symbol
new PhoneNumber("..."),
^
symbol: class PhoneNumber
location: class SmsSender
SmsSender.java:15: error: cannot find symbol
new PhoneNumber("..."),
^
symbol: class PhoneNumber
location: class SmsSender
SmsSender.java:13: error: cannot find symbol
Message message = Message.creator(
^
symbol: variable Message
location: class SmsSender
SmsSender.java:24: error: cannot find symbol
Message message = Message.creator(
^
symbol: class Message
location: class SmsSender
SmsSender.java:25: error: cannot find symbol
new PhoneNumber(n),
^
symbol: class PhoneNumber
location: class SmsSender
SmsSender.java:26: error: cannot find symbol
new PhoneNumber("..."),
^
symbol: class PhoneNumber
location: class SmsSender
SmsSender.java:24: error: cannot find symbol
Message message = Message.creator(
^
symbol: variable Message
location: class SmsSender
12 errors
error: compilation failed
I don't see any problem with your project setup. You can compare it to this reference project.
So, I suspect the problem you're seeing is related to how Eclipse imports Gradle projects. I'm not a regular Eclipse user but I did try it out for this question. When I imported the project in the above repo I saw import errors similar to yours. I was able to fix them by first telling Eclipse that this is a Gradle project (Project context menu > Configure > Add Gradle Nature) then refreshing the project (Project context menu > Gradle > Refresh Gradle Project). I got those steps from this answer. Then everything was working.
my routes file in play gives this error
**error: cannot find symbol
In /home/smat/practical/Stocks/conf/routes (line number not found)**
here is my routes file
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
# stocks
GET /stocks/add controllers.Stocks.add
POST /stocks/save controllers.Stocks.save
GET /register controllers.Stocks.registerUser
POST /register controllers.Stocks.registerUser
please help
sorry i forget to share errors on terminal
**[error] /home/smat/practical/Stocks/target/scala-2.11/src_managed/main/contrllers/routes.java:8:
error: cannot find symbol [error] public static final
contrllers.ReverseStocks Stocks = new contrllers.ReverseStocks();
[error] ^ [error] symbol: class
ReverseStocks [error] location: package contrllers
[error]
/home/smat/practical/Stocks/target/scala-2.11/src_managed/main/contrllers/routes.java:11:
error: package contrllers.javascript does not exist [error] public
static final contrllers.javascript.ReverseStocks Stocks = new
contrllers.javascript.ReverseStocks(); [error]
^ [error]
/home/smat/practical/Stocks/target/scala-2.11/src_managed/main/contrllers/routes.java:16:
error: package contrllers.ref does not exist [error] public static
final contrllers.ref.ReverseStocks Stocks = new
contrllers.ref.ReverseStocks(); [error]
^ [error]
/home/smat/practical/Stocks/target/scala-2.11/src_managed/main/contrllers/routes.java:8:
error: cannot find symbol [error] public static final
contrllers.ReverseStocks Stocks = new contrllers.ReverseStocks();
[error]
^ [error] symbol: class ReverseStocks [error] location: package
contrllers [error]
/home/smat/practical/Stocks/target/scala-2.11/src_managed/main/contrllers/routes.java:11:
error: package contrllers.javascript does not exist [error] public
static final contrllers.javascript.ReverseStocks Stocks = new
contrllers.javascript.ReverseStocks(); [error]
^ [error]
/home/smat/practical/Stocks/target/scala-2.11/src_managed/main/contrllers/routes.java:16:
error: package contrllers.ref does not exist [error] public static
final contrllers.ref.ReverseStocks Stocks = new
contrllers.ref.ReverseStocks(); [error]
^**
package contrllers.ref does not exist
It looks like you made a misspell somewhere in the source files. Try to lookup your project directories for files with "contrllers" instead of "controllers".