I have a Cordova project in Visual Studio 2015.
I've added some node modules, which doesn't display in project (in VS), but exists on disk, when all other files in project folder were added there by default without excluding.
So now I need a way to exclude node_modules from build, 'cause there're just dev tools (autoprefixer, less, watch, etc.), in case of that generated apk file size increases, which's not applicable for me (total size ~10MB, without node_modules - only 3MB). Does it really possible to do that without physical removing that folder? Maybe I don't know about some configurations or so on?
Final solution I found was to move node_modules to parent directory and fix paths in config files.
Related
When I build my Android application, I end up with 3 binaries in my APK for each architecture and I have android:extractNativeLibs="true" defined in my AndroidManifest.xml file. When I install the application I expect the binaries to end up in /data/app/my.app-base64==/lib/arm64 but instead:
If I install using IntelliJ run it works correctly.
Using adb install my.apk I get 1 of the binaries installed.
Installing from Google Play Store, none of the binaries are installed.
Can anyone help? I thought the issue was that the binaries were not called .so but it seems that even when they are, it doesn't help. I've also tried splitting the application into the different abi parts which works correctly but the install has the same problem.
2022-07-10
If you are using newer version of the Gradle plugin 4.0+, you may face issues when
your executable not being packaged into apk or extracted in.
/data/app/package/lib/.../...
There is a dirty trick for the Android Gradle plugin.
Solution:
1. Create a folder structure in your file explorer lib/armeabi/executable (I use armeabi just as an example, it can be your architecture), also do not make it end with .so
2. Now zip this lib folder and rename it to yournaming.jar
3. Copy and paste in your Android Studio libs directory
should look like this
4. Go to your build.grade(app), in dependencies section add following line
for compiling .jar.
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
...
}
5 Build your .apk and check with analyze tool, folder containing your lib/armeabi/executable should be now created in .apk itself.
My android app is having the usual Android Studio Folders but the size of certain folders exceeds the limit given by the IT for the projects which can be uploaded to the corporate repository.
Which All folders I can delete safely without breaking the build .I figure out build is the one. What else?
Below is the folder list :
- .gradle
- .idea
- build
- gradle
-keys
-res
-src
-Androidmanifest.xml
-ant.properties
-build.gradle
-custom_rules
-gradle.properties
-gradlew
-gradlew.bat
-local.properties
-proguard-project.txt
Use this site
https://www.gitignore.io/ to generate a .gitignore file for android e.g
https://www.gitignore.io/api/android
These are files that you can safely ignore to put on version control and still able to build your project anywhere.
I'm using crosswalk for an android app as per this guide.
While developing only with cordova (no xwalk), I could ignore certain files and folders on build by using aapt.ignore.assets in the ant.properties config file, to exclude the files that I didn't want packaged - i.e. node_modules. When using crosswalk this file is completely ignored for me.
In the build process the .dotfiles are automatically excluded, but as per npm specifications the node_modules folder cannot be renamed in any way. There are a few files that I wouldn't like to package on every build, especially since the build fails if the node_modules is included, throwing me this error:
/mypath/Sdk/tools/ant/build.xml:932: The following error occurred while executing this line:
/mypath/Sdk/tools/ant/build.xml:950: null returned: 1
...
/mypath/release-multi/cordova/node_modules/q/q.js:126
Currently while I develop I've gotta remove and re-add the folder every time I have to test a build and it's a complete hassle.
Any other while to forcefully exclude a list of files on build? I'm not an android dev -- currently only working with webapps.
Every project created in Android Studio 1.0.2 contains several files that reference the project's own absolute path. I can't even move my own project directory if I want to, let alone share the project with other developers.
Excluding files in app/build, these are the files containing absolute paths:
.idea/workspace.xml
.idea/modules.xml
.idea/libraries/support_v4_21_0_3.xml
.idea/libraries/appcompat_v7_21_0_3.xml
.idea/gradle.xml
.gradle/2.2.1/taskArtifacts/taskArtifacts.bin
.gradle/2.2.1/taskArtifacts/fileSnapshots.bin
app/app.iml
How do I force Android Studio to use relative paths for everything?
Edit: By experimenting with vanilla IDEA, I've narrowed down the origin of these absolute paths to a specific type of module, which Android Studio apparently always uses without offering you a choice. But I'm still no closer to understanding how to eradicate them.
In IDEA 14.0.2, if you create an empty project or an Android project with an "Application Module", the project does not contain any absolute paths. If you create a project with a "Gradle: Android Module", then it contains absolute paths in the same files as an Android Studio project.
Edit #2: Created IDEA-134587
In general, don't consider any of the .iml files or the contents of the .idea folder to be part of the project, and don't share any of those files, don't check them into source control, and don't move them with the project. Think of them as cache files.
The Gradle files are the source of truth, so if you're having troubles with absolute paths, close the project, delete the non-shareable files, and re-import it from the Gradle build scripts.
I ran into the exact same problem, but the solution suggested above contradicts JetBrains' advice as well as this answer. Also, my co-worker working from the same source code (with unexpanded paths) and Android Studio version wasn't having the problem, so I kept banging my head against the wall.
We eventually solved the problem when we realized that many of the paths I used included symlinks. In my case, I had a symlink set up for ~/work so that it pointed to /some/drive/with/space. Within Android Studio all of my source was referred to from ~/work/source rather than /some/drive/with/space/source. When I changed everything so that Android Studio referred to things with their actual paths, the $PROJECT_DIR$ and $MODULE_DIR$ variables magically started working and my .iml files were no longer getting corrupted. YMMV.
TL;DR: Don't use symlinks in your project paths!
Also, be sure to not keep the files within .gradle as part of your shared project.
Also, one set of files that you might want to share though are your files under .idea/copyright though as that allows you to have shared copyright settings.
So a possible .gitignore file might be:
.gradle
.idea
!.idea/copyright/[YourCopyrightFile].xml
!.idea/copyright/profile_settings.xml
*.iml
build
local.properties
Hmm. I just don't see the same absolute paths in those files, I only see references to MODULE_DIR and PROJECT_DIR, such as:
./app/app.iml: <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
or:
./.idea/workspace.xml: <entry file="file://$PROJECT_DIR$/.idea/libraries/appcompat_v7_21_0_2.xml">
I wonder if this is Linux issue only, or something in your settings?
I'm trying to learn android development and I am initially confused by the different project structures between Eclipse and Android Studio. This makes it difficult to follow tutorials designed for Eclipse. Could anyone let me know why these differences exist? Should they exist?
For instance, if I were to locate the R.java file in the two different IDEs, the paths would look like this:
Eclipse: app\gen\com.example.app\R.java
Android Studio: app\build\source\r\debug\com.example.app\R.java
Why are these paths different? Why is my R.java located in a debug folder in Android Studio? This lead to some errors early on, and if anyone has any insight into these differences I would appreciate them.
The mystery: Android Studio's Project Structure and Build System
I don't know if this is because of the Gradle Build System (I'd wager it is), but I'll tell you what I've understood so far.
Update 4: 2014/09/11 Added Cheat Sheet for BuildTypes, Flavors and Variants(I finally feel confident to write this :D)
Update 3: 2014/09/11 Updated the comparison workspaces and projects to be precise
Update 2: 2014/04/17 Added more detail to AS project structure
Update 1: 2013/07/29 Added IntelliJ Project Structure
The IntelliJ's Project structure (shown at the end) is for IntelliJ with the android plugin. The Android Studio, however, has a project structure divided like so:
Structure: Projects and Modules
module in Android Studio is like a project in Eclipse
project in Android Studio is like a workspace in Eclipse (to be precise, a workspace with interdependent projects)
From the documentation (Android Studio is based on Intellij IDEA) :
Whatever you do in IntelliJ IDEA, you do that in the context of a
project. A project is an organizational unit that represents a
complete software solution.
Your finished product may be decomposed into a series of discrete,
isolated modules, but it's a project definition that brings them
together and ties them into a greater whole.
For Android, it means one project per app, and one module per library and per test app.
There are multiple issues if you try to build multiple apps within the same project. It's possible, but if you try (like I did), you will see that almost everything is designed to work with a single app per project.
For example, there is an option to "rebuild the project", which makes no sense with multiple apps, many other project settings would be useless, and the built-in VCS system isn't great when you have multiple repositories.
Structure: Folder Structure
Top Level Folders
1. Main Project
This would be entire project context (Eclipse Land: Like your workspace but limited to what's relevant to your project). Ex: HelloWorldProject if the name of the application you gave was HelloWorld
2. .idea
This where project specific metadata is stored by Android Studio (AS). (Eclipse Land: project.properties file)
3. Project Module
This is the actual project. ex: HelloWorld if your application name you gave was HelloWorld
4. gradle
This is where the gradle build system's jar wrapper i.e. this jar is how AS communicates with gradle installed in Windows (the OS in my case).
5. External Libraries
This is not actually a folder but a place where Referenced Libraries (Eclipse Land: Referenced Libraries) are shown. Here's where the Targeted Platform is shown etc.
[Side note: This where many of us in Eclipse Land used to delete the referenced libraries and Fix Project Properties to fix reference errors, remember?]
Project Folder in Detail
This is number #3 in the above list. Has the following sub dirs
1. build
This has all the complete output of the make process i.e. classes.dex, compiled classes and resources, etc.
In the Android Studio GUI, only a few folders are shown. The important part is that your R.java is found here under build/source/<flavor>/r/<build type(optional)>/<package>/R.java
2. libs
This is the standard libs folder that you see in eclipse land too
3. src
Here, you only see the java and res folder which correspond to the src folder and res folder in Eclipse Land. This is much welcomed simplification IMHO.
Note on Modules:
Modules are like Eclipse Land projects. Here the idea is that you have one application project (Module #3 in the list above) and several library projects(as separate Modules under the global project folder (#1 in the above list)) which the application project depends on. How these library projects can be re-used in other applications, I still haven't found out.
[Side note: The whole re-organization has some benefits like simplifications in src folder, but so many complications. The complications are mainly due VERY VERY thin documentation on this new project layout.]
The New Build System
User Guide for the new Build System
Explanation of flavors and buildTypes, etc - What is the hullabaloo about?
CheatSheet for flavors and buildTypes
BuildType: debug and release are buildTypes available by default on all projects. They are for building/compiling the SAME CODE to generate different APKs. For example on release APKs you would want to run proguard(for obfuscation), sign it with your key (as against the debug key), run optimizations (maybe via proguard or other tools), use slightly different packageNames (we use com.company.product for release and com.company.product.debug for debug), etc. We also use a debug flag (BuildConfig.DEBUG) to turn off logging to logcat (since it makes the app slow) on release builds. This makes for a faster debug build during development but also an optimized release build to put on play store.
Product Flavor: There are no default flavors available (or to be precise, the default flavor is blank/nameless). Flavors could be free version or paid version where they have DIFFERENT CODE. They share the same Main Code but different versions(or no versions) of a few source code files or resources.
BuildVariant: A buildVariant is what a generated APK actually corresponds to. They are named like so (in order) Product Flavor + Build Type = Build Variant.
Example 1: if you have free and paid as two flavors. The build variants you would get are:
Free - debug
Free - release
Paid - debug
Paid - release
So that is 4 possible APK configurations. A few configurations may not make sense in a particular project, but they are available.
Example 2: (for new projects/ no flavors) You have 2 buildVariants or APKs available, since the default flavor is nameless/blank:
debug
release
Compare this with Intellij's Project Structure if that helps:
The .idea (1) folder contains a number of subfolders, mainly with internal IntelliJ IDEA information.
The src (2) folder contains the MyActivity.java (3) file source code that implements the functionality of your application. The file belongs to the com.example package.
The res (4) folder contains various visual resources.
The layout/main.xml file (5) defines the appearance of the application constituted of resources of various types.
The values folder (6) is intended for storing .xml files that describe resources of various types. Presently, the folder contains a strings.xml file with String resources definitions. As you will see from the Adding a Color section, the layout folder can also contain, for example, a descriptor of colors.
The drawable folder (7) contains images.
The gen (8) folder contains the R.java (9) file that links the visual resources and the Java source code. As you will see from the sections below, IntelliJ IDEA supports tight integration between static resources and R.java. As soon as any resources are added or removed, the corresponding classes and class fields in R.java are automatically generated or removed accordingly. The R.java file also belongs to the com.example package.
Android Studio: app\build\source\r\debug\com.example.app\R.java
Why are these paths different? Why is my R.java located in a debug folder in Android Studio? This lead to some errors early on, and if anyone has any insight into these differences I would appreciate them.
Simply put, Android Studio is configured to build a debug Build Type on your system.
Eclipse/ADT is designed to support a single build at a time (from what I can tell). One of the primary goals of the new build system (from the user guide):
Make it easy to create several variants of an application,
either for multi-apk distribution or for different flavors of an application
So where as Eclipse/ADT could generate one R.java file, Android Studio supports multiple. The generated R.java is located in the debug folder because by default the new build system supports debug and release build types off the bat. If you changed your build variant (button, lower left hand corner of AS) to release AS will generate R.java in the release directory.
This might not mean anything for simple projects, but the support of Build Variants means a drastic simplification of the build process for many developers, including the project I'm working on.
Our project supports 4 flavors with 2 build types (debug and release), to support a total of 8 different APK combinations. And each of those combinations have slightly different configurations, so this build system really worked out for us. My android studio is installed on a different machine, but if memory serves my correctly the R.java file exists in build/source/<flavor>/r/<build type>/package/R.java. When our CI server builds the APK files it uses each of these R.java files to generate separate packages.
Google Discontinue the support for the Android Developer Tools
(ADT) in Eclipse is ending, per our announcement. You should migrate
your app development projects to Android Studio as soon as possible.
For more information on transitioning to Android Studio, see Migrating
to Android Studio.
So best for Android development tool for Android Studio only for all future support of Android M ---
For android Studio 3.0.1 and selected all features:
Android O latest
Android Auto
Android things
Android wear
Android TV
C++ support
Kotlin support
The structure in version 3.0.1 does not look at all like all other answers.
Recent structure is as displayed in 2018, Android Studio 3.0.1 01/2018.
Newbie kinda found something resembling to usable in feature sub-folder:
Update your Android Studio 3.0.1 01_2018:
ToolTip: