I just created an Android Project in Eclipse with all the phonegap and cordova files as expected. However, I have no such directory, and thus, no config.xml. According to the Apache Cordova documentation, it is supposed to be located at: app/res/xml/config.xml.
My folder structure is as follows, for the /res directory:
/res/drawable-hdpi
/res/drawable-ldpi
/res/drawable-mdpi
/res/drawable-mdpi
/res/layout
- /res/layout/main.xml
/res/values
- /res/layout/strings.xml
What have I done wrong or what step am I missing? I hope I have provided enough information.
Just create the /res/xml/ folder manually. Then create config.xml using a text editor and use this as a template: https://github.com/phonegap/phonegap/blob/master/lib/android/xml/config.xml
Whenever we create a cordova project, config.xml gets created automatically. We need to check if there is any folder in excluded list.
Go to Build path -> Resources -> Check for excluded resources.
Remove them from the project and build the project. You will be able to view the config.xml and www folder in the Project/Package Explorer.
Related
I have cordova latest version installed on my system and I created the basic app with command
cordova create
and I added the platform using
cordova add platform android
and I replaced the default index.html in the www directory with my own index.html
but whenever i tried to generate apk, and tried to run it on my mobile. It was the apk generate with default index.html
the screen of my app will be
How to resolve this issue ?
This is a normal behaviour.
Cordova is going to take the index.html from your projects root folder, everytime you run cordova build, prepare or serve without attribues, which is located directly inside your projects www folder.
Root www folder inside your cordova project contains the index.html which is taken and "thrown" into all platform folders when you run those commands.
projectName -> www -> index.html
Solution
You work in your projects root folder, and run cordova prepare everytime after you did a change to your index.html file.
You work directly inside your android project folder and the index.html which is located inside the assets -> www folder
You can change default index.html file to your own .html file
Simply open config.xml file in your project folder and edit its src attribute in <content> tag:
like:
default:
content src="index.html"
edited:
content src="helloCounterApp.html"
(Then it will load helloCounterApp.html not index.html(default))
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.
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.
When you create a phonegap project you start off with a root www folder, among other files.
/www
You then need to add devices to work, for example andriod or IOS. This then creates a new www folder inside the respective playforms:
\platforms\android\assets\www
My question is, when using Android Studio how are you meant to use the root www folder? If at all? Which www folder am I meant to be building with?
It appears that when importing with Android Studio to go straight to the platform/andriod.
You should be editing the files in the /www/ file. When the CLI tools run prepare, which happens a lot, these files are copied into the appropriate platform's /www/ file. (This is because each platform can have it's web assets in a different location.) So do all of your work in the main /www/ folder - this is the one you should be putting into version control.
For more information try reading the documentation guide about The config.xml file which describes some of this: http://cordova.apache.org/docs/en/3.1.0/config_ref_index.md.html#The%20config.xml%20File
I've also written up a pretty long answer in another question that is pretty similar: Should a phonegap plugin be declared in the config.xml file?
In Eclipse (on Windows) I created a cross-platform folder structure for Phonegap :
--phonegap_android
--assets
--www (symlink/junction to 'src')
...
--phonegap_ios
...
--src
index.html
Here's what I did to get this working :
created an Android-project in Eclipse based on the phonegap-android
folder.
made a junction for the 'assets/www' folder to link with 'src' (using the Sysinternals command)
created a svn-repository, for this entire project (the parent project that has the different folders for android, ios and src).
I can run the application now, but I have problems committing the project to svn.
The 'www' folder is a junction-folder, so when changes are made to this folder, I want this folder to commit to the real source folder : 'src'.
I tried different approaches :
Setting an svn:ignore on 'assets' to ignore 'www', but then of course
nothing in www is committed, when I commit the android-project in Eclipse.
Setting an svn:externals on 'assets' to define 'www' as an
external to svn://myproject/src, but then it still tries to commit everything in assets/www and I get an error 'No versioned parent directories'.
Any ideas how to get the www folder NOT committed, but at the same time get the src folder to get committed to the svn repository?
Dylan,
Following with svn:externals will work.
Create Folder 'phonegap_android'
Under 'phonegap_android' create folder 'assets'
Commit them to svn repository 'svn://myproject/phonegap_android'
Now for the 'phonegap_android' folder, set the svn:externals as follow
'../src assets/www'(if your svn path for src is at same level as phonegap-android svn://myproject/src which is in your case)
On windows using tortoise svn, it will let you commit 'phonegap_android' folder with svn:external changes.
Take svn updates and you are done.
Henceforth whatever you commit to phonegap_android/asset/www folder, it will be committed to src folder(svn://myproject/src)