I am managing and running my android app from command line without using ant, I followed these steps:
generate R.java
compile R.java and all .java files in src to .class files
assembling set of class files into dex file using the command below
dx --dex --verbose --output=./bin/classes.dex ./bin
.class files are in bin directory.
But I'm getting the following errors in these steps:
java.lang.Runtime exception:.\bin file not found
at com.android.dx.cf.direct.ClassPathOpener.process
at com.android.dx.command.dexer.Main.processOne
at com.android.dx.command.dexer.Main.processAllFiles
at com.android.dx.command.dexer.Main..run
at com.android.dx.command.dexer.Main.main
at com.android.dx.command.Main.main
Due to this, I'm unable to create the Classes.dex file.
Can someone suggest a solution for this?
[not using eclipse and ant only through command line]
If you need to "manage your Android projects from command line", when you should use Ant build.
Ant's build.xml is a official standardized way to build Android projects. Ant scripts can do anything you may need to build your project.
If you want most modern build tools for Android, you can look at Gradle for Android projects. Note: today it's still in alpha stage.
Try entering the full path instead of the relative path.
Also you must put the class files inside a directory named exactly like it's package name. for example for com.test.me.MyActivity you must use com/test/me/MyActivity.class
And since we are on the topic, remember that dx can only work with class files created using Java6 (or less) so if you are using java7 to compile your code, add "source 1.6 target 1.6" parameters to your command line.
Related
I want to build aar files but I dont have Android Studio as my computer cannot run it.
How to build it from command line using the raw build tools; no gradle included?
The steps to build apk are:
generate R.java file with (aapt).
compile src files including R.java with (javac)
dex classes with (dx)
package, sign, align.
I understand that aar manifest(s) are not compiled to binary format. Thus the first step may not work when creating aar libs.
Please, I am begging, how to, the steps to creating with the build tools.
./gradlew <moduleName>:bundle<build_variant>Aar
//for example
./gradlew app:bundleReleaseAar
How can I build an APK file from the command line? I've tried
MSBuild myProject.dproj /p:Config=Release /p:Platform=Android
but no APK file is produced, only the .so file.
Some experimentation shows that the following aspects of the various proposed courses of action come into play for a more complete picture.
When you create a new Delphi multi-target project (let's call it Foo) you have one MSBuild-compatible file created: the Foo.dproj Delphi project file. In the case of Android (the platform in this question) this is enough to build the target libFoo.so library file that would eventually become part of a deployed .apk file, but is not enough to make the .apk file just yet.
You can build your .so file, which contains the ARM machine code, using a command line like this:
msbuild Foo.dproj /property:Config=Debug /property:Platform=Android /target:Build
or this more concise version:
msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Build
As per the documentation you can use the Deployment Manager's Deploy button to create an additional MSBuild file, or indeed just choose the Project, Deploy libFoo.so menu item. The initial step of this deployment is to create a Foo.deployproj file, which is another MSBuild-compatible file.
With Foo.deployproj file present this following line will take the libFoo.so file and anything else required for deployment and use these to build up the .apk Android application package file:
msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Deploy
The Deploy target will fail if the required files such as libFoo.so are not present, say by previously running MSBuild using the Build or Make MSBuild targets: s(431,5): error : Required local file "Android\Debug\libFoo.so" not found. Deployment failed.
Additionally the Deploy target fails if you have not got a Foo.deployproj file generated for your project: error MSB4057: The target "Deploy" does not exist in the project.
That said, if you have the Foo.deployproj present you can build and deploy in one fell swoop with something like:
msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Build;Deploy
Of course to avoid compiling files that have not changed this is perhaps better:
msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Make;Deploy
The fact that the documentation doesn't mention anything about the Deploy target is a little confusing. There is potential to think that it implies you run MSBuild against Foo.deployproj file, but that yields no joy whatsoever. It seems the documentation is out of date or plain wrong.
I found:
MSBuild Project1.dproj /p:Config=Debug /p:Platform=Android /t:Deploy
I have a number of projects that I work on simultaneously.
Every time I build and run one of them, the apk is located as usual in the bin folder.
If I want to copy this apk to some other folder outside the project, I have to do it manually.
I created a single batch file that copies all my projects' apk files to the desired location.
Is there a way to change the output location of the bin folder to somewhere outside the project or more preferably run the batch file after each build?
NOTICE
I am using eclipse with ADT. I have tried to add a builder that executes the batch file. However, when the batch file is run, the apk file is not yet generated. I tried all combinations of options in the builder and all the possible of sequences of builders.
If you are happy just to use Eclipse whilst you are perfecting the build, then switching to the command line for the final build, then with Ant it's really easy to get what you want with very little effort or configuration.
Assumptions
1) Your sources are in an Android workspace and you will end up with two sets of binaries - one made by Eclipse, the other made by Ant will end up outside the workspace as set by a PROPERTIES file
2) You are using SDK14 or 15 (Ant changed in 14)
3) You have Ant installed and in your path - you'll need to have Ant 1.8.2 - this is not the internal one that Eclipse uses, you may have to get it from the Apache site, it's easy to install
Steps
1) Make a sample project from the command line as described in http://developer.android.com/guide/developing/projects/projects-cmdline.html
For example I used:
android create project --target 8 --name Sample15App --path c:\dev
\projects\samples\Sample15 --activity Sample15Activity --package com.me.samplefifteen
This will make a directory and some files which you will use later as a template in your projects
2) Make a sample project in your workspace from Eclipse, I made EclipseSample in one of my workspaces
3) Copy the following files from Sample15App to the root of your EclipseSample project:
build.xml
ant.properties
local.properties
4) Edit ant.properties (which is initially empty) to be like this example:
projectname=EclipseSample
workspace.dir=/dev/projects/EclipseIndigo/AndroidWorkTwo
base.dir=${workspace.dir}/${projectname}
outbasebase.dir=/dev/projects/AntBuilds
outbase.dir=${outbasebase.dir}/${projectname}
ant.project.name=${projectname}
out.dir=${outbase.dir}/bin
layout.dir=${base.dir}/res/layout
source.dir=${base.dir}/src
From this you can see that my workspace is /dev/projects/EclipseIndigo/AndroidWorkTwo
The eclipse project under this is in directory EclipseSample
I want my apks to end up in /dev/projects/AntBuilds/EclipseSample (i.e outbasebase concatenated with projectname -so for other projects you can use a very similar ant.properties file just change projectname)
5) IMPORTANT - EDIT THE build.xml
Comment out or remove the line :
<project name="Sample15App" default="help">
replace it with just
<project>
This just means it will pick up the project name from ant.properties rather than the build.xml and you can use the same build.xml in all your projects, only ant.properties need change
6) try it with "ant debug" should build the debug apks under /dev/projects/AntBuilds/EclipseSample
7) finally if you want to automate the release build (signing and password entering automatically) add lines like
key.store.password=YourPassword
key.alias.password=YourPassword
key.store=c:/users/you/yourrelease-key.keystore
key.alias=release_alias
to the ant.properties and then you just type "ant release"
If you don't add them it will tell you to sign manually and as no password entries were found in 'build.properties' (- that was what ant.properties used to be called pre SDK 14, they should have corrected this!)
You can add new Builders to your project using Project Properties->Builders->New....
One way to do this is to create an ant build (which copies the file), or just a plain old script or batch file.
I would like to generate some .jar for tools to include in an Android project.
So I use command tool "javac" which works great.
But when I try to use Android SDK, it fails:
C:\Dev\Tools.java:123: package android.util does not exist
android.util.Log.d("MYTAG", "hello !");
To compile, I use this command:
"C:\Program Files (x86)\Java\jdk1.6.0_23\bin\javac.exe" -g -d C:\Gen C:\Dev\Tools.java
Any help?
"javac" is the Java compiler, not the tool used to create JAR files, so just compiling a class does not generate a jar file
To be able to compile a class, you must also tell the compiler where it can find the required libraries. This is automatically done for system libraries, but you'll have to pass the path to the Android libraries. This can be done by specifying the folders/jar files using the -classpath parameter on the command line, or by adding it to the respective CLASSPATH environment variable.
I maintain an Android app and am not using Eclipse. I am not using Eclipse. I am using ant and build.xml and build.properties.
I have places my .jar file into the libs/ directory. My code compiles just dandy. But when I run it on the emulator, the output APK does not include the .jar, so I get a runtime stacktrace:
ERROR/AndroidRuntime(470): java.lang.NoClassDefFoundError: com.google.ads.AdView
my build.properties looks like this:
jar.libs.dir=libs
And the libs/ directory contains my .jar file.
What needs to be in build.xml so that the external .jar file is included in the APK?
Edit: In theory this answer should work, but it doesn't for me. Is it out of date? What gives? How to add external jar libraries to an android project from the command line
I just came over a similar problem and noticed that libraries should not be placed in "myprojectdir\lib". When I moved them to "myprojectdir\libs" everything started to work.
It turns out that I needed to upgrade the version of ant I was using to 1.8. During the compile process, I had been getting this error message:
Warning: Reference out.dex.jar.input.ref has not been set at runtime,
but was found duringbuild file parsing, attempting to resolve. Future
versions of Ant may support referencing ids defined in non-executed
targets.
I googled it, and found that I needed to upgrade Ant, and now I don't get this warning, and my application does not force close.
What needs to be in build.xml so that the external .jar file is included in the APK?
Just putting it in libs/ is sufficient.
my build.properties looks like this:
That line should not be necessary. It does not appear in my build.properties files that build successfully with JAR files.
If you use dexdump -f classes.dex from your project's bin/ directory, you will be able to determine whether com.google.ads.AdView made it in there. If it did not, then something is strange with your build scripts. If it did, then perhaps there is a dependent JAR that you are missing (though I would expect a VerifyError in that case).
You use 3rd party library, but you seem didn't run DX on it. Make sure that not only your code processed by DX tool (I assume Ant does it), but also all 3rd party libraries you use. You can look in 7Bee script I use to convert web applications to Android davlik format, so it can work for you too. You can find more about the script on Atjeews page.
Solution:
right click on the project in project tree and select Project
properties
select Java Build Path
select TAB Order
and Export
check GoogleAdMobAdsSdk-4.0.4.jar (or your
version SDK)
press OK
clean project by menu Project
-> Clean
rebuild project (Project – Build Automatically)