Flutter - 3rd party JAR code will run from within Android Studio but not from VS Code - flutter

I'm using VS Code to develop a test flutter app that uses Symbol/Zebra's EMDK to interact with a barcode scanner. This involves some custom code on the Android side, which has been implemented, and if I open the Android code within Android Studio and run it on my device everything works fine, but if I then go back to my VS Code and try to run the flutter project I get an error "Unfortunately app has stopped". I suspect this is more of an issue around the 3rd part JAR file not being included when run from the VS code side, but I'm not familiar enough with where I need to include it (Gradle, IML files) in order to make it work. Any help would be appreciated.

You can create a libs folder, for example, which should be at android/libs and place your jar file there. Then add the following to your android/build.gradle file at the bottom:
dependencies {
implementation fileTree(include: '*.jar', dir: 'libs')
}

Related

Android Studio not creating main.dart file

I'm new to programming so please be genetle. I'm handy with computers though and I've been sitting on this problem for a few weeks while learning flutter and dart
When I create a new flutter application in android studio, it does not create a main.dart file - the libs foder is empty, and I also see no IOS folder. In fact, what I see looks VERY different from any tutorials I've seen !!
What I do see is a bunh of .xml files, including one called activity main which runs a main activity function which almost seems like it is there instead of the main.dart file I'm looking for.
I have run flutter doctor, apparently everything is good.I have the dart and futter plugins installed. It is not a case of selecting "project" from the drop down menu instead of "Android" which is a common answer online. Not sure what I'm missing !!
Any help would be really really appreciated as I'm learning to code to open my next business and I am struggling to get over the first hurdle.... at leasr I am proficient wit dartpad now though :P
EDIT:
When I click on 'file > new > new flutter project', I don't see an option for "flutter application". This is what I see...
enter image description here
If I create a flutter project at this point, this is what Android Studio looks like for me...
enter image description here
If you have properly created a Flutter project in Android studio, main.dart file should be very easy to locate. It is located in project_name -> lib -> main.dart, as follows:
I am sharing steps to create flutter project in android studio :
Step 1: Open the IDE and select Start a new Flutter project.
Step 2: Select the Flutter Application as the project type. Then click Next.
Step 3: Verify the Flutter SDK path specifies the SDK’s location (select Install SDK… if the text field is blank).
Step 4: Enter a project name (for example, myapp). Then click Next.
Step 5: Click Finish.
Step 6: Wait for Android Studio to install the SDK and create the project.
Note: When creating a new Flutter app, some Flutter IDE plugins ask for a company domain name in reverse order, something like com.example. The company domain name and project name are used together as the package name for Android (the Bundle ID for iOS) when the app is released. If you think that the app might be released, it’s better to specify the package name now. The package name can’t be changed once the app is released, so make the name unique.
The above steps create a Flutter project directory called flutter_app that contains a simple demo app that uses Material Components.
Running the application:
Follow the below steps to run the flutter application that was structured above:
Step 1: Locate the main Android Studio toolbar:
Step 2: In the target selector, select an Android device for running the app. If none are listed as available, select Tools> Android > AVD Manager and create one there. For details, see Managing AVDs.
Step 3: Click the run icon in the toolbar, or invoke the menu item Run > Run.
After the app build completes, you’ll see the starter app on your device.
as per screen shot shared by you click on flutter , hopefully this will create a new flutter project.

Could not read script 'C:\flutter\packages\flutter_tools\gradle\app_plugin_loader.gradle' as it does not exist

I get this error when i run a project on VS code.
Could not read script 'C:\flutter\packages\flutter_tools\gradle\app_plugin_loader.gradle' as it does not exist.
How can i solve it?
Try flutter pub cache repair this should re-download all the packages and fix any package issues.
try deleting the android folder
and run flutter create . from the same level as the android folder
For android studio Problem is because Android Studio doesn't know where Flutter is installed in your machine. Same applies to visual studio flutter... You need to explicitly specify this in local.properties file like I've done below. (If you have already specified it, make sure you go to that location on your PC to be sure that the location was 100% correct and its all there):
(Values used in code below is Just for example.. See my picture for how it looks on an actual machine)
sdk.dir=C:\Users\location of where your android sdk is
flutter.versionName=1.2.0 flutter.sdk=C:\Users\location of where
your flutter is
Picture example

Flutter error: Unable to locate gradlew script

I can't run all of my flutter apps, because in the console appears everytime this error message:
Downloading Gradle Wrapper... 1,2s
Launching lib\main.dart on SM G960F in debug mode...
Running Gradle task 'assembleDebug'...
Finished with error: Unable to locate gradlew script. Please check that C:\Users\...\android\gradlew.bat exists or that C:\Users\...\android can be read.
I try to fix this problem more than ten hours and don't find a solution.
I will advise you to check your pc properly for unwanted programs. Something is preventing your pc from running the Gradle. I had the same issue only to realize that antivirus was installed on my pc alongside a cd burner that I just installed. Check for any antivirus that might be preventing Gradle from running.
I also faced the same error initially. While creating a flutter application from scratch I just ran the default flutter application which is a counter app in a flutter. I faced the same issue at first. If you are in this same context as described earlier the following could be the solution
1.Java 8 is more suitable for the flutter/android development. The next versions of java have some exceptions. I used the Java 14 and stuck at this issue for some time
The next could be the JAVA_HOME path in your environment variables. If it is not provided the set the JAVA_HOME path.
Run flutter --doctor and check the requirements if satisfied like Android SDK is updated or not, upgrade flutter if required. In some cases having good Internet connection also plays a role in this issue some times.
These are the major points to be satisfied in order to get rid of this error. Mostly this could be the a solution or part of it.
The error suggests that something is preventing gradle to run properly on your machine. Check whether you have any unwanted programs or anti-virus on your machine running that might be preventing gradle to run. If so, remove or stop those programs / anti-virus and try again.
After that, delete the .gradle folder located here C:\Users\yourPcName\.gradle containing the unfinished file and try again . It will work now .
You can also manually download Gradle and map it in Android studio , Learn more with this article here .
Warning, the gradle versions change quickly, so make sure you manually
downloaded the exact version that flutter wanted to download and the
download failed. Download the gradle here and then replace it in the
gradle folder.
C:\Users\yourPcName\.gradle\wrapper\dists\gradle-x.x.x-all
If it still doesn't work,
Try to run flutter --doctor
From a console window that has the Flutter directory in the path (see above), run the following command to see if there are any platform dependencies you need to complete the setup:
C:\src\flutter> : flutter doctor
This command checks your environment and displays a report of the status of your Flutter installation. Check the output carefully for other software you might need to install or further tasks to perform (shown in bold text).
You can learn more here :
If flutter doctor itself doesn't work, then know that flutter is not installed on your machine (or you forgot to add it to the environment
variable).
I also faced this problem and I made something to run my app on android
tried to open anything on android files and android studio ask me if I want to open for editing android file in android studio then click on it and it will open android project then click run enter image description here

Gradle Android SDK integration with Unity [duplicate]

My project uses these plugins:
OneSignal
GooglePlayServices
Adjust
Google Analytics
Unity IAP
Facebook SDK
Those plugins are used in almost every project.
But I am over field references count
This is my .aar file list
What should I do to decrease reference count?
So What should i do to decrease reference count ?
You have so many plugins with many functions/fields. There is a limit when building this from Unity's Editor and you have reached that limit.
To decrease reference count, you have to delete some these plugins but I am sure that you need them and deletion may not be the appropriate solution in this case.
The only way to actually get around this and build for Android at this moment is to export the Project as Android Project then build it with Android Studio. This removes the reference limit imposed by Unity's Editor.
EDIT
I forgot to mention that you have to enable multidex after exporting it out. Since many people go through this problem daily, I decided to add a thorough instruction on how to fix this problem by exporting it out and also how to fix it without exporting it.
FIX BY EXPORTING THE PROJECT
1A.Export the Unity Project as Android Project.
1B.Import into Android Studio:
If you get grade error when importing into Android Studio like the one below:
Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection
cannot be cast to
org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
In the "dependencies" block which is in the "buildscript" block in the build.gradle file, change:
classpath 'com.android.tools.build.gradle.2.1.0'
to
classpath 'com.android.tools.build:gradle:2.2.3'
If you export the Project and still get the-same error, you need to manually enable multidex. Below is a simplified step to follow from Google's doc that will be shown to you in the error:
2.Add android:name="android.support.multidex.MultiDexApplication" > to the
application tag in the AndroidManifest.xml file.
3.Add compile 'com.android.support:multidex:1.0.1' to the "dependencies" block in the build.gradle file.
4.Add multiDexEnabled true to the "defaultConfig" block which is in the "android" block in the build.gradle file.
Build APK and see if it works. If the reference count error is gone, stop here.
5.Getting a GC overhead exception like the one below?
java.lang.OutOfMemoryError: GC overhead limit exceeded
Increase the heap size that will be used when performing dex operation. From this solution, add the following to the "android" block in the build.gradle file:
dexOptions {
javaMaxHeapSize "4g"
}
FIX WITHOUT EXPORTING THE PROJECT
Must have Unity 5.5 and above to do this:
1.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates, Copy the mainTemplate.gradle file to your <ProjectName>Assets\Plugins\Android folder.
2.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Apk, Copy the AndroidManifest.xml file to your <ProjectName>Assets\Plugins\Android
3.Open both the mainTemplate.gradle and AndroidManifest.xml file you just copied with Visual Studio then do the modification from the FIX BY EXPORTING THE PROJECT instruction above. Skip/Ignore step #1A and #1B. Just do steps from #2 to #5. That's it.
This is what the final mainTemplate.gradle should look like and this is what the final AndroidManifest.xml should look like. This is only for reference purposes. I suggest you don't use mine but instead follow the copy steps above to create yours because future Unity versions can come with different files. You want to make sure you use the latest one or you may have problems building it.
4.Build APK and see if it works:
--
If the reference count error is gone, stop here:
5.Getting an error like the one below?
Build Failure Release builds have to be signed when using Gradle
Just sign the apk from the Publishing Settings in the Build Settings. You can create new keystore or use an existing one.
6.Another error like below?
Error: Avoid hardcoding the debug mode; leaving it out allows debug
and release builds to automatically assign one [HardcodedDebugMode]
Remove android:debuggable="true"> from the AndroidManifest.xml file.
If this non exporting solution did not work for you then you have to
use the exporting solution.
IMO, The accepted answer isn't correct (or only partly correct). Exporting an Android studio will not "magically" fix this issue. Also, from my experience, the exported Android studio project does not always build right away and you have to fix lots of things before you can actually build it.
You are using lots of plugins and so you faced an Android limitation of not being able to reference more than 64k methods.
There are a few things you can try to solve this:
Delete some of these plugins, if possible (as already suggested in the accepted answer).
Use multidex. In the past this was only possible by exporting the project to Android studio and building it there. Starting with Unity 5.5 you can build your project using Gradle right from Unity. This means you can create a custom gradle file that configures your game to use Multidex. This doesn't reduce the method ref count, but it works around it by splitting your native Java count into multiple dex files.
Use ProGuard - since you can use Gradle from Unity, you can also define ProGuard to run and remove any code that is not used.

using libGDX/gradle with Netbeans

I want to learn to use libGDX to create android apps/games.
I used the installer from the libGDX website to create a new project, installed gradle (on windows10) and am able to build/run my project through command line. (tested desktop version and apk via bluestacks, both work nice)
My problem is now, that Netbeans cannot display my code correctly. It says cannot access java.lang at the first line, and things like cannot find symbol, package * does not exist or Override is not an annotation type at the other errors.
I mean, it works somehow, but it's not nice development like that. How can i fix those errors?