In my flutter project when I run either :
./gradlew build
or
gradle build
I get this type of error :
.dart_tool/flutter_build/generated_main.dart:11:8: Error: Error when reading 'lib/main.dart': Le fichier sp├®cifi├® est introuvable.
This is because my main.dart is located in "lib/src/main" instead of "lib" , and it needs to stays that way.
When I run my build with flutter I use an option to specify the main location :
flutter build apk -t "lib/src/main/main.dart"
And it works fine.
Is there such option for./gradlew build or gradle build ?
Thanks.
Here's the answer...
./gradlew build -Ptarget=lib/entry_point_name.dart
The -P indicates gradle that what follows is a project parameter, in this case the parameter's name is 'target'. This parameter is used to override the default main.dart entry point.
If you are using android studio then follow these steps:
1: Go to edit configurations
2: Change the entry point
Thats it.
Related
I was trying to add opencv 4.5.2 into my android studio project. But I am getting errors when I try to run the application. There was no error before that.
Steps that I followed to add opencv:
File -> New -> Import Module and then I selected the sdk folder that was inside the extracted folder of opencv-4.5.2-android-sdk (that I downloaded from opencv.org/releases/) and I gave it name openCVLibrary452 and then I clicked on finish.
File -> Project Structure -> Add Dependency and then I selected openCVLibrary452 from the list and clicked Apply and Ok.
Now I added below line inside my MainActivity onCreate()
Log.e("TAG", "OpenCV initialized : "+ OpenCVLoader.initDebug());
When I try to run the app this is the error I get:
[CXX1405] error when building with cmake using F:\StudioProjects\KingScanner\openCVLibrary452\libcxx_helper\CMakeLists.txt: Build command failed.
Error while executing process E:\Android_sdk\cmake\3.18.1\bin\cmake.exe with arguments {-HF:\StudioProjects\KingScanner\openCVLibrary452\libcxx_helper -DCMAKE_SYSTEM_NAME=Android -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_SYSTEM_VERSION=21 -DANDROID_PLATFORM=android-21 -DANDROID_ABI=arm64-v8a -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DANDROID_NDK=E:\Android_sdk\ndk\21.4.7075529 -DCMAKE_ANDROID_NDK=E:\Android_sdk\ndk\21.4.7075529 -DCMAKE_TOOLCHAIN_FILE=E:\Android_sdk\ndk\21.4.7075529\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=E:\Android_sdk\cmake\3.18.1\bin\ninja.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=F:\StudioProjects\KingScanner\openCVLibrary452\build\intermediates\cxx\Debug\6n761z2d\obj\arm64-v8a -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=F:\StudioProjects\KingScanner\openCVLibrary452\build\intermediates\cxx\Debug\6n761z2d\obj\arm64-v8a -DCMAKE_BUILD_TYPE=Debug -BF:\StudioProjects\KingScanner\openCVLibrary452\.cxx\Debug\6n761z2d\arm64-v8a -GNinja -DANDROID_STL=c++_shared}
This is my first time adding opencv to my project. Can you please tell me what am I missing here.
Any help would be much appreciated. Thank you.
It doesn't fix the issue with your compiler, but if you just want to use OpenCV you can put this dependency in your build.gradle:
implementation 'ai.eye2you:opencv-android:4.5.2'
And then just initialize it with your code or with System.loadLibrary("opencv_java4").
The key is "not" to rename the sdk folder. It is because OpenCV hardcoded the path with the name of “sdk” in the native/jni/OpenCVConfig.cmake.
I am trying to run the default app which comes when creating a flutter file using "flutter run" but it gives me the following error:The error I am facing.
I did try installing gradle, creating a settings.gradle file in my root directory of project and run "gradle wrapper" it was successful but I still face the same error.
UPDATE: One of my parent directories had spaces in the directory name. After removing the spaces it solved the issue.
Your gradle-wrapper is missing. Make sure that you've a gradle distribution added in your PATH variable and restore the wrapper by running this command:
gradle wrapper
I'm building app using different ways, two works but one fails.
Method:1 (Working)
flutter build appbundle
Method:2 (Working)
Opening module in Android Studio, after that, choosing
Build > Generate Signed Bundle/APK... > filling all info afterwards
In this case, I am able to build both app bundle and APK file.
Method:3 (Not working)
flutter build apk
I get this error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android_intent'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
If I remove android_intent, I start getting error in other packages, so definitely the package isn't a problem. I double checked that I have
local.properties, gradle.properties and settings.gradle in my android root folder.
And my other projects seem to work.
I have faced this issue with file_picker plugin, Just upgrade gradle version in android/build.gradle to one of these versions :
3.3.3
3.4.3
3.5.4
3.6.4
4.0.1
I followed this link : file_picker troubleshooting
I recommend clearing the android-studio-dir and android-sdk settings, and let flutter automatically detects their path instead: This works for me .
flutter config --android-studio-dir=""
flutter config --android-sdk=""
Sometimes you will see an SDK problem from a plugin that requires the latest gradle to actually run.
I was running into this even though my SDK was properly set:
SDK location not found. Define location with sdk.dir in the
local.properties file or with an ANDROID_HOME environment variable.
More info from:
Here is an example of a plugin failure that will lead to an sdk and query error flutter_file_picker:
Build is failing with unexpected element <queries> found in <manifest>.
Upgrade gradle:
To upgrade gradle in a flutter project, File -> Open and select the Android folder which is part of your Flutter application. When that finishes loading, it will prompt you to upgrade gradle to the latest version. This will resolve the issue
I had the same problem.
In my case, an outdated package was the cause of the problem
To fix this issue try to upgrade the Gradle version to the latest version.
For doing this go to android/gradle/wrapper/gradle-wrapper.properties and then, replace the version of distributionUrl with the latest Gradel version.
for example:
upgrade:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
to:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
I was facing the same issue but there is a file create in
build\app\outputs\apk\release\app-release.apk
which when installed works fine without any issue . Even I don't know why this happens but it works.
So in my case what I feel is happening is that there is a conflict between the new build and the already existing build due to a new package or something else so I did
flutter clean and tried building again and voila it worked.
In android\gradle.properties make sure android.enableR8 is NOT set to false. It may just be related to your apk size, not a specific package.
I had the same issue. Here how I solved it.
Make sure you have a file called local.properties in android folder, and make sure it has a correct Computer user name such as like that:
sdk.dir=C:\\Users\\YOURUSERNAME\\AppData\\Local\\Android\\Sdk
flutter.sdk=C:\\src\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.5
flutter.versionCode=10
for MAC, path should be like that
sdk.dir = /Users/YOURUSERNAME/Library/Android/sdk
In case if this doesn't work, add ANDROID_HOME variable in "Environment Variables" as C:\Users\YOURUSERNAME\AppData\Local\Android\Sdk
in mac os.
open terminal and run below command
nano ~/.bash_profile
type below values in terminal with your user_name
export ANDROID_HOME="/Users/<user_name>/Library/Android/sdk"
export ANDROID_TOOLS="/Users/<user_name>/Library/Android/sdk/tools/"
export ANDROID_PLATFORM_TOOLS="/Users/<user_name>/Library/Android/sdk/platform-tools/"
and save them by control+X and then Enter
after that restart terminal and type below command
source ~/.bash_profile
finally type
echo $ANDROID_HOME
I have to do it on my project folder then it worked for me.
My build.gradle for an Android app has become quite lengthy. Chanced upon this plugin called gradle-lint-plugin and configured it properly. In its documentation it says
Run ./gradlew fixGradleLint to automatically fix your build scripts
but upon running that I get Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain.
Does this have anything to do with the Android Studio using its own Gradle plugin? I do not have Gradle installed systemwide.
Edit: I do not wish to install Gradle systemwide - is there any way to do this within Android Studio only?
Sounds like the wrapper is not setup correctly. Likely missing the wrapper jar.
$ ls gradle/wrapper
gradle-wrapper.jar gradle-wrapper.properties
When you look in gradle/wrapper do you see gradle-wrapper.jar?
if you install gradle you can generate the jar with this command:
$ gradle wrapper
I was having this error and I solved it correcting the path which had special caracters.
Ex: .../T&G/appmobile
to ../TG/appmobile
This sometimes happens if you have "&" or "/" kind of special characters in your folder or in the parent folder. Rename those folders and the error is simply gone.
I'm trying to launch phonegap android app in android sdk, but I am receiving an error:
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] compiling Android...
[error] An error occurred while building the android project.Error executing "ant debug -f "/Users/me/Projects/one/platforms/android/build.xml"":
BUILD FAILED
/Applications/Android/adt-bundle-mac-x86_64-20131030/sdk/tools/ant/build.xml:932: The following error occurred while executing this line:
/Applications/Android/adt-bundle-mac-x86_64-20131030/sdk/tools/ant/build.xml:950: null returned: 1
I followed this guide http://docs.phonegap.com/en/2.2.0/guide_getting-started_android_index.md.html but it is not working.
What could have caused this?
You are most likely also getting the line
invalid resource directory name:
/YOUR/PROJECT/ROOT/PATH/bin/res/crunch
right before the error codes, so open up terminal and enter the following:
cd YOUR/PROJECT/ROOT/PATH
rm -fR $(find . -type d -name crunch|xargs)
I just had to cd into the platforms/android dir and run ant clean and it fixed this issue for me.
had the same issue. something that can help is to read ant log as recommend here
to do so run ant -logfile //antLogFile.txt release -f ./AppMain/build.xml
or in the folder itself. i.e : platforms\android run ant -logfile ./antLogFile.txt release
My issue was a file with Hebrew characters on its name..
Hi Sorry for the late answer
An alternative to other solutions possibly OS-X Specific but i was having the same issue and none of the solutions for me worked however the mention of assets made me go back and scour over my build logs and i noted this:
[aapt] /Users/rowdoggnz/Development/cordova/surveyapp/platforms/android/assets/www/lib/fa/Icon
[aapt] : error: Invalid filename. Unable to add.
This was the cause of my error which shared the same error code and line references as the original poster.
OS-X seems to generate ghost icon files for some reason which are not visible in finder due to being hidden, i used an app called "Invisiblix" to view my project folder and removed all of the 'Icon' files and my app would build fine.
I'm guessing the iOS build naturally ignores these Icon files however Ant doesn't.
Hope this helps someone.
If you have more than one project and you are using the same assets eg: images, ant will fail to build. You can use ant clean to remove the cache from other projects and avoid this issue as suggested in this post crunch/resource packaging with aapt in ant build uses cache from other projects
Nevertheless, In my case I just have one project with many images, some of them were called with the same name, but with different letter case. Ant's build process is case-insensitive, so those images were duplicated, being error cause.
My particular fix was to rename or eliminate one of the images to allow cordova build my project.
I was having this issue in OSX using Ionic framework. This was my fix:
I ran this on the command line in the project root folder:
find . -name Icon -exec rm {} \;
What the above does descend through the whole project to search for files name Icon. Upon finding them they are deleted.
After this I ran my build process and all was good again.
Make sure you have installed the prerequisites correctly.