can we exclude a particular file alone while building apk in flutter - flutter

There is 2 product flavour in my project and i do not want some files to be added while building the .apk or app bundle and the below solution is not working .
android {
packagingOptions {
exclude 'lib/widgets/hotel.dart'
exclude 'lib/widgets/hotel_list_view.dart'
exclude 'lib/widgets/hotel_list_data.dart'
exclude 'lib/widgets/smooth_star_rating.dart'
}
}

You do not need to worry about that the files which are not used will automatically removed from the code

Related

Exclude file from apk when building with Soong

With regular gradle app I am able to exclude a file from apk (native lib specifically) with this, but at the same time keep another native lib called say mylib2.so in the apk.
packagingOptions {
exclude "**/mylib1.so"
}
Is there a possibility to do the same using AOSP Soong build system when describing android_app type of module?
The goal is to have mylib1.so shared among many apps and exclude it, but mylib2.so is app specific and it's better to be in the apk.

How to remove default assets from ionic 2 build?

I am learning Ionic 2; writing code in Visual Studio code. I created project using following command:
> ionic start --v2 MyFirstIonic blank
And then
> cd MyFirstIonic
> ionic platform add android
When I build and run, > ionic run android, ionic creates assets folder in www directory and copies font files for Ionicons, Roboto, and Noto-sans, which are added in apk during build process. I'd like to exclude Ionicons, Roboto, and Noto-Sans from final build, and use FontAwesome files instead. How will I be able to achieve this?
You need to edit your node_modules/#ionic/app-scripts/copy.config.js.
Sample file here.
Remove copyFonts entry :
copyFonts: {
src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
dest: '{{WWW}}/assets/fonts'
},
from the file. This copies the ionicon fonts to your www folder.
Also remove the assets you do not need from src/assets folder.
You can edit copy.config.js file to add any other assets into the build process.
Refer answers here.
I would suggest you delete the unnecessary files from:
[project]/node_modules/ionic-angular/fonts/
(Keep the ionicons.* files.)
You'll still have to do that every time you update ionic-angular but it's easier and less error prone than keeping track of changes to the app-scripts bundle.
Additionally, comment out the roboto and noto-sans imports in:
[project]/src/theme/variables.scss
--
If you still want to update the script then the right way to do that is to copy the file locally as [project]/src/webpack.config.js and add the following entry to your package.json:
"config": {
"ionic_webpack": "./webpack.config.js"
}
--
Hope that helps!

How to cherry pick ZIP contents with Gradle Distribution plugin?

My Gradle build currently produces the following directory structure under a build dir in my project root:
myapp/
src/
build.gradle
build/
docs/
groovydoc/* (all Groovydocs)
libs/
myapp-SNAPSHOT.jar
myapp-SNAPSHOT-sources.jar
reports/
codenarc/
main.html
test-results/* (JUnit test results)
I would like to add the distribution plugin (or anything that accomplishes my goals, really) to have Gradle produce a ZIP file with the following directory structure:
myapp-SNAPSHOT-buildreport.zip/
tests/
(JUnit tests from build/test-results above)
reports/
main.html (CodeNarc report from build/reports/codenarc above)
api/
(Groovydocs from build/docs above)
source/
myapp-SNAPSHOT-sources.jar (from build/libs above)
bin/
myapp-SNAPSHOT.jar (from build/libs above)
After reading the plugin's documentation, I can't tell how to configure it to suit these needs. Its obvious that I need to run gradle distZip, but as to how to actually configure it to produce the desired directory structure, it doesn't seem to provide any documentation/examples. Any ideas?
Note: The JAR's version is obviously SNAPSHOT, and is passed into the Gradle build with a -Pversion=SNAPSHOT command-line argument.
The Gradle Distribution plugin automatically has defaults (the problem is that the docs do not tell us the defaults, but the Gradle project default structure is what is assumed) so if your Gradle project is fairly straightforward and already using src/main/groovy or src/main/java, you typically just need to...
Use the CopySpec reversing pattern of giving your into{} (makes a dir) containing the contents of from{} , rather than the reverse, like so:
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'application'
distributions {
main {
baseName= 'vz_sde_dm'
contents {
into('bin/config') {
from 'config'
}
into('lib/samples') {
from 'samples'
}
}
}
}
Notice I did not need to define a from{} for my contents{}, but only into{}s that's because I am already using the default Gradle Groovy project layout and only added 2 extra folders (config & samples) under my project in Eclipse but needed those 2 folders to land into a slightly different hierarchy for my Distribution compared to my regular build folder layout.
I would probably not use the distribution plugin and instead just create a new custom Zip task. It would look something like this:
task buildreportZip(type: Zip, dependsOn: build) {
classifier = 'buildreport'
from('build/test-results') {
into 'tests'
}
from('build/reports/codenarc') {
into 'reports'
}
from('build/docs') {
into 'api'
}
from(sourcesJar) { // or whatever you source jar task name is
into 'source'
}
from(jar) {
into 'bin'
}
}
I was trying to make a custom layout also, and had real trouble figuring out how to exclude the project output from build/libs from the yourProject.zip/yourProject/lib directory (and excluding things in general) and putting it instead into yourProject.zip/yourProject.
After quite a few hours across multiple days of searching and poking around in the API I finally found something that worked using actual configurations of the Distribution and underlying CopySpec (documented here and here, respectively for Gradle 5.6.1, you can just replace 5.6.1 with current in the URL to get the most recent API docs, 5.6.1 just happens to be the version I'm using):
distributions {
main {
baseName = appName
contents {
filesMatching("**/${appName}.jar", {
if (it.getPath().contains('/lib/')) {
it.setPath(it.getPath().replace('lib/', ''))
}
})
into('config') {
exclude(['server.crt', 'spotbugs-exclusion-filters.xml'])
from 'src/main/resources'
}
}
}
}
For exclusions the only thing that worked was matching on a glob pattern and specifying the correct action (to copy it to the root dist directory instead of root/lib) with a Closure through the filesMatching method of the main distribution's content CopySpec. You can see also how destination for configs is changed from the root to the root/config directory. Thanks so Thad's answer for helping to guide me to the correct build configuration, also.

Migrating Eclipse Android Junit Tests into Android Studio Gradle

We are trying to migrate our Eclipse projects using ant builds into Android Studio using gradle. So far all is good except for our JUnit tests that use external json files. We have a ton of these where the the external file is located in the same directory as the java file. Is there a way to keep the java code and the json file in the same location and just modify the build scripts in gradle?
Current build directory is something like this \com\pack\krf\ contains MyFileTest.java and data.json. Source code to load json is this:
getClass().getResourceAsStream("data.json");
I do not want to change 300+ java files that have this same structure. Plus I do not want to group into the resource directory in gradle since some of these files will have the same name.
Here's the solution one of my teammates came up with. Add this to your build.gradle file after the android declaration. The print path is for debugging.
task alterResourcePath << {
sourceSets.testDebug.resources.srcDir('src/test/java')
sourceSets.testDebug.resources.srcDirs.each {
File f->
if(f.exists()){
println f.path
}
}
}
test.dependsOn alterResourcePath
By default gradle (like Maven) puts the resources under src/main/resources, so you'll have to tell Gradle to look for them in src/<something>/java instead:
android {
sourceSets {
instrumentTest {
resources {
srcDirs = ['src/instrumentTest/java']
}
}
}
}
if you are running robolectric test you do the same, but the robolectric plugins out there uses standard java source sets. So you won't do this inside the Android extension:
sourceSets {
test {
resources {
srcDirs = ['src/test/java']
}
}
}
If you use other sourceSets (per flavor or per build Type) you'll need to update those as well.

Unable to get files in Android assets directory

I am trying to find files located in assets. I have .txt, .gif, and .db files that are there in an eclipse android project but do not display when I run the following code:
AssetManager am = getAssets();
try {
String list[] = am.list("/");
I=0;
Str="";
while (list[] != null) {
Str=Str+"\r\n"+list[I];
I++;
}
}
catch(exception e){
}
I get this list:
AndroidManifest.xml
META-INF
assets
classes.dex
com
res
resources.arsc
This list does not include any of the files in assets.
Project properties is currently set to not include assets folder in the build path. When I do include the assets folder in the build path, it gives me the same list with ".." as the first file.
I have tried changing "/" in the third line to "/assets/" but get nothing returned.
Changing the Android Project Build Target between Android 2.3.1 and Android 2.1-update1 appears to have no effect.
Is there a setting in the project properties that is required for files in assets to be included in the build? Is there a different name for the assets directory using AssetManager?
list() takes a relative path within the assets. Seems in your case you need to pass an empty string, am.list("")