I am trying to generate apk file using command prompt by following below blog.
Generate APK using command prompt
I successfully generated key, but when i am trying to generate R.java it is giving following error
Command i used to generate R.java:-
E:\ADT\adt-bundle-windows-x86_64-20140702\sdk\build-tools\19.0.0>aapt com.concep
t.build -v -f -m -S E:\AppBuilder\res -J E:\AppBuilder\gen -M E:\AppBuilder\Andr
oidManifest.xml -I E:\ADT\adt-bundle-windows-x86_64-20140702\sdk\platforms\andro
id-19\android.jar
Error:-
**Crunching PNG Files in source dir: E:\AppBuilder\res
To destination dir: (null)**
Please tell me what wrong i am doing .
OR
Can Please help me how to generate apk using command prompt.
Related
We have a great build system, so we're not looking to use gradle. Right now, we use appt to build an APK and it works great and the APK runs well. I see that aapt2 is the future, though, and so we'd like to move to it before we're forced to.
What we currently do:
We have a simple icon in res/mipmap/our_icon.png
We have our ./AndroidManifest.xml file
We have our libMyApp.so stored in apk/lib/armeabi-v7a/libMyApp.so
We build using the following command: aapt package -f -M AndroidManifest.xml -S ./res -I /opt/android-sdk/platforms/android-28/android.jar -F my app-unsigned.apk apk/
We then zipalign and sign using apksigner and the app loads just fine. As you can see, all very simple and gives us just what we need.
I've tried the following with aapt2, but of course it is incorrect:
aapt2 compile ./res/mipmap/our_icon.png -o ./compiled
aapt2 link -v -I /opt/android-sdk/platforms/android-28/android.jar -I compiled/mipmap_our_icon.png.flat --manifest AndroidManifest.xml -o MyApp-unsigned.apk
note: including compiled/minmap_our_icon.png.flat.
error: failed to open APK: Invalid file.
You're trying to provide the resources the way you'd provide an APK (e.g. android.jar):
-I compiled/mipmap_our_icon.png.flat
To pass compiled resources use the -R flag (per each resource or use the wildcard * if you want to pass the whole directory, e.g. compiled/*).
You can find more info on differences between aapt and aapt2 in my old answer here.
I am using FlatBuffer 1.8 release (windows flatc)
Here are few commands which i have tried in cmd windows.
C:\>C:\Flat\flatc.exe flatbuffer -b -j "C:\Akash\FlatBuffer\app\src\main\res\raw\sample_schema.fbs" "C:\Akash\FlatBuffer\app\src\main\res\raw\sample_json.json"
one more using flatbuffer jar file
C:\>C:\Akash\FlatBuffer\app\libs>flatbuffers-java-1.3.0-SNAPSHOT.jar flatc C:\Akash\FlatBuffer\app\src\main\res\raw\job_schema.fbs C:\Akash\FlatBuffer\app\src\main\res\raw\job.json
which gives me following error
sample_schema.fbs & sample_json.json is available on this link
What am I missing here?
Your command includes the word flatbuffer, which does not fit the specification of the command:
flatc.exe [OPTION]... FILE... [-- FILE...]
To fix the command, remove that word:
C:>C:\Flat\flatc.exe -b -j "C:\Akash\FlatBuffer\app\src\main\res\raw\sample_schema.fbs" "C:\Akash\FlatBuffer\app\src\main\res\raw\sample_json.json"
With this example, three files should be created: Friend.java, People.java, PeopleList.java, and sample_json.bin.
As you can see from the project below, I want to know how to generate the java file in the gen folder:
Create R.java
In order for the application source code to be able to access the resources within the res/ directory, a class called R.java (for Resources) is created.
Use the Android Asset Packaging Tool (aapt) to create the R.java file:
ANDROID_HOME/platform-tools/aapt
package
-v
-f
-m
-S DEV_HOME/res
-J DEV_HOME/src
-M DEV_HOME/AndroidManifest.xml
-I ANDROID_HOME/platforms/android-7/android.jar
Building Android programs on the command line
please tell me how to build apk files of a project without the use of ECLIPSE ide. i found some infos about using a batch file but i don't know how to remake it.
echo on
SET PREV_PATH=%CD%
cd /d %0\..
REM Clear bin folder
rmdir "bin" /S /Q
rmdir "gen" /S /Q
mkdir "bin" || goto EXIT
mkdir "gen" || goto EXIT
REM Set your application name
SET APP_NAME=SecureSms
REM Define minimal Android revision
SET ANDROID_REV=android-8
REM Define aapt add command
SET ANDROID_AAPT_ADD="%ANDROID-SDK%\platforms\%ANDROID_REV%\tools\aapt.exe" add
REM Define aapt pack and generate resources command
SET ANDROID_AAPT_PACK="%ANDROID-SDK%\platforms\%ANDROID_REV%\tools\aapt.exe" package -v -f -I "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar"
REM Define class file generator command
SET ANDROID_DX="%ANDROID-SDK%\platform-tools\dx.bat" --dex
REM Define Java compiler command
SET JAVAC="%JAVABIN%\javac.exe" -classpath "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar"
SET JAVAC_BUILD=%JAVAC% -sourcepath "src;gen" -d "bin"
REM Generate R class and pack resources and assets into resources.ap_ file
call %ANDROID_AAPT_PACK% -M "AndroidManifest.xml" -A "assets" -S "res" -m -J "gen" -F "bin\resources.ap_" || goto EXIT
REM Compile sources. All *.class files will be put into the bin folder
call %JAVAC_BUILD% src\org\secure\sms\*.java || goto EXIT
REM Generate dex files with compiled Java classes
call %ANDROID_DX% --output="%CD%\bin\classes.dex" %CD%\bin || goto EXIT
REM Recources file need to be copied. This is needed for signing.
copy "%CD%\bin\resources.ap_" "%CD%\bin\%APP_NAME%.ap_" || goto EXIT
REM Add generated classes.dex file into application package
call %ANDROID_AAPT_ADD% "%CD%\bin\%APP_NAME%.ap_" "%CD%\bin\classes.dex" || goto EXIT
REM Create signed Android application from *.ap_ file. Output and Input files must be different.
call "%JAVABIN%\jarsigner" -keystore "%CD%\keystore\my-release-key.keystore" -storepass "password" -keypass "password" -signedjar "%CD%\bin\%APP_NAME%.apk" "%CD%\bin\%APP_NAME%.ap_" "alias_name" || goto EXIT
REM Delete temp file
del "bin\%APP_NAME%.ap_"
:EXIT
cd "%PREV_PATH%"
ENDLOCAL
exit /b %ERRORLEVEL%
i got this codes from a site. (http://www.apriorit.com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line)
i downloaded the source code sample and opened the batch file in there but it didn't generate it's apk file. usually the apk file is located at its bin\ right? but when i opened the folder, the file is not in there. please help me how to use this one. i'd appreciate you help.
You’ll have to have Apache ant for this one:
ant debug
This will build and sign the necessary .apk files.
For more info, please see this: http://codeseekah.com/2012/02/09/command-line-android-development-basics/
EDIT:
ant is not a part of standard Android SDK setup. You'll have to install it.
Download the latest ant zip file from The Apache Ant Project.
Extract the zip file to a folder, say c:\ant\
Add c:\ant to your path environment variable
Once these are done, you'll be able to run ant from the command line
The apk by default is located under bin and this is correct, but when you distribute source code it's better to not add any apk because a "fresh" compiled apk is always a better solution.
if you have a file called build.xml in the root of your project just do
ant debug
otherwise you need to update your project with the minimum informations required for the building phase with
android update project -t android-10 -p .
in this case android-10 is a target for your apk/app/api and you can customize this option for your targeted device.
After this you get your build.xml and everything is in place for generating an apk.
ant debug install
is actually viable if you create project with (note that you should specify the virtual device with "adb -s" command while installing if you're running multiple devices)
android create project -n <project_name>
-t <target_version> -p <path> -k <package> -a <activity>
and use this command to run on the avd (if you've started one)
adb -e shell "am start -a android.intent.action.MAIN -n com.your.package/.YourActivity"
(change -e option to -d if you're running on devices)
reference
better use "AVD Manager.exe" to start a virtual device if you don't know those command or parameters, as there're quite a lot.
One of the best example I found on Internet for creating Android APK is https://geosoft.no/development/android.html.Also you can use assembleDebug command in root directory (make sure setting gradle as environment variable), if you are using Gradle.
I tried to run rake run:android the follwing occurs, kindly assist me.
AndroidManifest change file [C:/Users/giridhran/workspace/myfirst/bin/libs/relea
se/arm-linux-androideabi/4.4.3/extensions/AndroidManifest.xml] from native exten
sion not found !
delete original manifest
Manifest updated by extension saved!
EXT: add additional files to project before build
PWD: C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rhodes-3.3.2
CMD: D:/installer/android-sdk_r11-windows/android-sdk-windows/platform-tools/aap
t.exe package -f -M C:/Users/giridhran/workspace/myfirst/bin/tmp/AndroidManifest
.xml -S C:/Users/giridhran/workspace/myfirst/bin/tmp/res -A C:/RhoStudio/ruby/li
b/ruby/gems/1.8/gems/rhodes-3.3.2/platform/android/Rhodes/assets -I D:/installer
/android-sdk_r11-windows/android-sdk-windows/platforms/android-8/android.jar -J
C:/Users/giridhran/workspace/myfirst/bin/tmp
C:\Users\giridhran\workspace\myfirst\bin\tmp\AndroidManifest.xml:30: error: No r
esource identifier found for attribute 'xlargeScreens' in package 'android'
Error in AAPT
Before running rake run:android command, please ensure that:
you have set the path of java-bin folder.
you have set the path of Android SDK & NDK.
check the android version in build.xml file.