Is there a script or something that creates a new Android project in Terminal IDE on Android? How does the R file get updated with new resources?
This might help : http://developer.android.com/tools/projects/projects-cmdline.html
It will create a project that can be used...with ant.
Maven has an archetype system that can create a new Android project : https://github.com/akquinet/android-archetypes
There doesn't seem to be any gradle equivalent (yet).
You need to create your project's home folder and then create the
./src
./dist
./res
./build
./build/classes
directories and add an "AndroidManifest.xml" file manually.
It works. Copy the "builder.sh" script in the project's home folder and make the proper changes like cd into your project's home folder, set your project's package name and select the main activity class.
As per your question about the R.java file, the aapt tool from Android SDK detects the changes in resources and writes R.java file and packs resources accordingly.
Related
I'm new to Android development, and I'm trying to manage projects from the command line using the SDK since I cannot get Android Studio 1.2 to work properly in my system (it's unresponsive).
The problem: I created a new project but the asset folder is missing.
Other SO answers (enter link description here) solve this by creating the folder from the IDE, or by pointing to the asset folder in the .iml file, with doesn't work in my case (I trying to mange the projects from the command line entirely)
There's also a solution editing build.gradle, but the project created from command line (using the SDK) doesn't seem to be a gradle project.
Any help would be appreciated.
Just create a directory called "assets" at the root of your project, i.e. in the same directory your AndroidManifest.xml lives. There's no need to "link that folder from the project". At least that's the case on my system, where I'm using Android SDK 24.4.1 (and I'm not using Gradle -- just emacs and ant).
Once I had assets/fonts/aisauc.ttf in there, the following code...
import android.graphics.Typeface;
...
Typeface greek =
Typeface.createFromAsset(getAssets(), "fonts/aisauc.ttf");
mytextfield.setTypeface(greek);
gave me a TextField with characters from the font I wanted.
How do I create the assets folder manually?
You make it the same you make any directory on your filesystem. Whether you use mkdir or a command-line equivalent, or whether you use your desktop OS's file manager, is up to you.
The default location for an assets/ directory is in a sourceset (e.g., src/main/assets/, to go along with src/main/AndroidManifest.xml and src/main/res/ and src/main/java/, where src/main/ is a sourceset). You can have an assets/ directory located elsewhere, if you choose, but then you will need to configure your build.gradle file to teach Gradle the alternative assets/ location for whatever sourceset you are trying to apply it to.
In your left most sidebar or the sidebar that shows the app, manifests, java... etc, right click app > New > Folder (has the green android symbol next to it) > Assets Folder.
On the next screen leave the path as 'main' and click 'Finish'. Then you can drop whatever asset you want into the folder.
I am new to Android Studio.
My questions are :
what is the difference between src/androidTest and src/main folders ?
where should put all my classes ?
Refer Android Studio Overview
Each instance of Android Studio contains a project with one or more application modules. Each application module folder contains the complete source sets for that module, including src/main/ and src/androidTest/directories. For the most part, you will need to modify the files under each module's src/main/ directory for source code updates, the gradle.build file for build specification and the files under src/androidTest/ directory for test case creation.
In Android Studio 1.0 the scheme has changed a little bit.
Your path should be (app)/src/androidTest/java/com/myapp/HelloWorldTest.java
Here's how I set up Unit Tests in a new Android Studio project:
Open app in Android Studio.
Set the Project explorer (left hand window) to display 'Project' mode.
Tap the little drop-down at the top left and select 'Project'.
Right click the 'src' directory, 'New -> Directory'.
Call new directory androidTest
Right click androidTest and add a 'java' directory.
It will appear in green (indicating it's a test src directory).
Now right-click again and add a package, e.g. com.mycompany.myapp.tests
Add a new class that extends AndroidTestCase.
http://envyandroid.com/content/images/2014/02/project-structure.png
For putting the classes:-
src folder --> main folder --> then java
To be precise on androidTest:
Unit tests run on a local JVM on your development machine. Gradle plugin will compile source code found in src/test/ and execute it using the usual Gradle testing mechanisms.
To answer in a word. The main difference between androidTest and android and main folders is the former is for "Testing" while the later is for Development.
I found a library on git. https://github.com/flavienlaurent/NotBoringActionBar
after imported to the eclipse, I noticed that the src folder is empty and there is a folder called java. Tried to run it anyway but it gave me an error.
Do I have to make some changes before running it?
The project you are trying to import is developed with Android studio, so there is some extra files in it.
To import it in your eclipse you need to import it as normal android project. now your src folder is empty and you have an extra folder named java
copy com package from java folder and paste it in src folder
Delete java and bin folder
Clean and build your project
Run on emulator or device
The Project you are trying to import is a project based on Gradle build system developed using Android Studio.
In such project everything related to code is in App/src/main
/java contains all .java files
/res same as res in eclipse
AndroidManifest.xml
So easiest solution is create a new project in eclipse and copy paste the file accordingly,
In you case
Copy the src/com directory in /src in eclipse
Copy the /res in to /res directory of created project
Replace AndroidManifest.xml
But it is strongly recommended to migrate from Eclipse to Android Studio instead of doing all these because now all the libraries available are migrating in to gradle.
I am creating an Android library and it has an assets folder with images.
When I use it in another project the assets doesn't get copied.
Anyone else had this issue?
The new Android Build System that is based on Gradle supports asset folders in library projects!
With ANT based builds it's still not possible:
Library projects cannot include raw assets. (See docs)
But you could
copy the assets manually
or even patch the aapt tool (see http://devmaze.wordpress.com/2011/06/26/enabling-assets-in-android-libraries/)
It is possible to put assets into resulting library jar by small fix:
Put "custom_rules.xml" into you library project home (near the build.xml):
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<target name="-post-compile" if="${project.is.library}">
<echo>Post Compile: add assests from ${asset.absolute.dir} to ${out.library.jar.file}</echo>
<jar destfile="${out.library.jar.file}" update="true">
<zipfileset dir="${asset.absolute.dir}" prefix="assets" excludes="**/*.java ${android.package.excludes}"/>
</jar>
</target>
This will pack your library assets into you resulting library jar. As result, these assets will be included into resulting .apk of your application.
Checked on Android SDK Tools Revision 21.1.0 on OSX
From Eclipse and ANT you can reference the same "assets" folder from multiple projects.
This allows your source tree to have a single copy of the assets files, but have them included in multiple APKs.
See Android: targeted res folders for debugging in eclipse
From ProjectA I was able to reference ..\ProjectA\Assets from ProjectB.
On Eclipse (under Windows at least, I've not tried on Linux yet), I had to create a new variable to reference ..\ProjectA and use that variable in "Linked Folder Location". If I attempted to use ".." in "Linked Folder Location" eclipse wouldn't accept it.
For those using IntelliJ IDEA, you can make a change to your application module's packaging settings to include depedent assets. Note, this was done on version 14.0.2 of IntelliJ Community edition. My main application module now inherits files form my library project's assets folder as if they were right in the main project!
Right click application module > Open Module SEttings. Select Android tree node on module > Packaging Tab. Check "Include assets from dependencies into APK"
Note: I've never used Android Studio, but I would guess there is a similar setting for this in that application.
start by creating android lib project, close after creation. this'll prevert autobuild
use cmd terminal on windows android command is batch file
add tools to path
C:\Users\user_bss>PATH=%PATH%;C:\adt-bundle-windows-x86-20140321\sdk\tools
Generate build.xml for ant
android update project -p C:\Users\user_bss\Documents\Workspace\SDKAdvanced -n SDKAdvanced
notepad custom_rules.xml add the code from above don't forget end tag
run "ant debug" or "ant release" to build
you'll see classes.jar in bin dir this is your packed lib
I'm using a default Eclipse project file generated for my Android application, and I want to keep it in a targets/ directory (along with other eclipse-specific files) in order to better organize my project structure (I also plan on adding a target for NetBeans).
Simple question, I suppose: Is this possible?
Coming back to this question, Ryan Conrad is correct in that Eclipse needs the .project files in the root of the project directory. As such it is not possible to move it elsewhere.
You can define target or output destination by change the output folder. I guess you can do that by change the dir path under Property of the Android project.
If you want to reorganize all your Eclipse projects, you can create a new workplace (Files/Switch workplace) and start creating new projects from now on.