Flutter build.gradle - flutter

I am a newbie to Flutter. Just wanna ask how many build.gradle files are in a Flutter project; what is Project-level and App-level build.gradle? Thanks in advance.
I found 2:
> android > app > build.gradle
> android > app > src > build.gradle

In a Flutter project, there are two build.gradle files: one at the project-level and one at the app-level.
The project-level build.gradle file is located in the root directory of your Flutter project and is used to define the properties and settings for the entire project. This file is usually used to configure the repositories and dependencies for your Flutter project as a whole.
The app-level build.gradle file is located in the android directory within your Flutter project and is used to define the properties and settings specific to your Android app. This file is used to configure the app-level dependencies and build settings.
So in summary, there are two build.gradle files in a Flutter project: one at the project-level and one at the app-level.

Related

Enable MultiDex in Unity Without using Gradle

I Use External Dependency Manager for Unity in my project. And I added my project dependencies in a .xml file instead of using Gradle. But now I got some error about MultiDex. Can I enable MultiDex in my project without using Gradle files?
D8: Cannot fit requested classes in a single dex file (# methods: 75121 > 65536)
You can set minimum android API level to 21(Android 5.0 - Lollipop) and multidex will automatically be enabled. You can set it at player setting -> other settings.

Flutter plugin that uses .aar modules builds and runs fine in the example app but fails to build in a different app

I've written a Flutter plugin to use an SDK that requires the inclusion of some .aar modules. It builds and runs perfectly in the example app for the plugin, but when I import the plugin in a different app and try to build it, the build immediately fails with a message saying that one of the .aar modules could not be found in the plugin. This makes no sense because the module is definitely there - the platform channels to use the SDK would fail in the example app if the module wasn't there.
Why would the example app build and run without any problems but a different app won't? The only thing I can think of is that I import the plugin from path in my pubspec but it seems unlikely to me that this is the culprit.
Any advice or assistance here would be appreciated. TIA!
I got it!!!!
The answer is as found here: How to add .aar dependency in library module?
The way this adapts to a Flutter plugin is as follows:
Add a libs folder at the root of the android project in the plugin. Add the .aar files there.
In the plugin's build.gradle file, update rootProject.allProjects to look as follows:
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
dirs project(':your_plugin_name_here').file('libs')
}
}
}
Still in the same build.gradle, add your .aar file(s) as dependencies as follows:
implementation(name:'aar_name_here', ext:'aar')
In the Flutter app that you want to use the plugin for, open the app-level build.gradle file and add the plugin itself as a dependency, like so:
android {
...
dependencies {
implementation project(':your_flutter_plugin');
}
}
In the settings.gradle file for the app that us using the plugin, change
include ':app'
to
include ':app', ':your_flutter_plugin'
And this should do it!!

Convert Facebook Android SDK .aar file to Java Library Project

I'm trying to convert facebook android sdk .aar file to Java Library Project (and use it in Unreal Engine 4 as OnlineSubsystem).
What i've done (according to this answer - AAR in Eclipse ANT project):
Download facebook-android-sdk-4.10.1, unzip it, rename facebook-android-sdk-4.10.1.aar to facebook-android-sdk-4.10.1.zip.
Unzip facebook-android-sdk-4.10.1.zip.
Create in Eclipse new android java library project.
Add classes.jar (from facebook-android-sdk-4.10.1.aar) to libs of Eclipse project.
Replace res folder of eclipse project with res folder of .aar file.
Create new android application and add facebook library project to android application project.
Copy all from facebook .aar's AndroidManifest.xml to android application project.
When I'm trying to build application I always get these errors:
res\layout\com_facebook_device_auth_dialog_fragment.xml:22: error: No resource identifier found for attribute 'cardBackgroundColor' in package 'com.facebook'
res\layout\com_facebook_device_auth_dialog_fragment.xml:22: error: No resource identifier found for attribute 'cardElevation' in package 'com.facebook'
The CardView declaration (with errors) look like this:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#android:color/transparent"
card_view:cardElevation="10dp">
When I delete these two attributes everything works fine, but I want to know how to build my project without deleting anything.
Unreal Engine uses ant build system for building android application so, please, do not offer me to use gradle.
Thanks.
I realized that I should add cardview java library project from android sdk (android-sdk\extras\android\support\v7\cardview) to my facebook java library project.
Thanks everyone.

Eclipse path issue of 'Generate Gradle Guild files'

I trying to convert my android Eclipse project to Android Studio project.
I updated the Android SDK Tools to 24.0.2, and export by clicking 'File > Export... > Android > Generate Gradle build files > Next > Next > Select Project(s)+lib(s) > Next > Finish'.
I can export build.gradle, setting.gradle, gradle(folder) ...
but all the exported files are in my 'Documents' folder not in the android project workspace.
Eclipse will auto generate 'Project root' e.g. '/User/usernaem xxxx/Documents' after select the project need to export.
How can I change the 'Project root' generated by Eclipse?
And I tried move those files: build.gradle, setting.gradle, gradle ... to a new folder
- updated "lasspath 'com.android.tools.build:gradle:1.0.0'" in build.gradle
- updated "distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip" in gradle-wrapper.properties
then import to Android Studio but fail (without error but project content not showing).
How can put the android studio project in old project workspace or in new folder?
Many thanks.

Building library project in Android Studio that has been imported from Eclipse

I have an Android library project in Eclipse that I am trying to build with Android Studio so I can generate an .aar file for my users.
The project seems to have been imported cleanly into Android Studio using the "Import Project" option in the welcome screen.
How do I now build the module? The instructions on the dev site say that I need to change:
apply plugin: 'android'
to
apply plugin: 'android-studio'
However my build.gradle file doesn't have that line (I would have assumed that the importer would have added it(?)).
If I insert the line apply plugin: 'android-library', and try to 'Sync Project with Gradle Files', I get the error:
Gradle 'MyProject' project refresh failed
Error:C:\Users\Fred\AndroidStudioProjects\MyProject\src\main\AndroidManifest.xml
(The system cannot find the path specified)
The same happens if I try to make the project anyway.
Here's what my build.gradle looks like:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android-library'
My searches to find a solution have failed. Anyone know what is going on?
I'm using the latest Android Studio (0.5.8)
Don't put the apply plugin: 'android-library' statement in the top-level build file. You should find an apply plugin statement in your module-level build file, and you can modify it there as necessary.
Okay. After some head scratching and more searching, I resolved all my problems I think. For the record:
I think my first import broke somehow. Partly because of the problem highlighted by Scott Barta and possibly because my project directory had spaces in it? Not totally sure.
A later import went more smoothly and I was able to sync and build without errors. However, apart from the build output in the Gradle Console, there was no evidence anything had actually happned. The artifact (ie. the .aar file) doesn't show up in the UI.
After finding this question: How to export library to Jar in Android Studio? I realised that the aar file is in fact built. It is just hidden from you. You have to root around in the file system to find the .aar. It is in:
<Library module>/build/libs/
Something that the docs don't tell you anywhere. Sigh.
Hope this helps someone else..