how to generate other class file besides R.java? - android

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

Related

Convert APK to manifest in a loop

I have many APK (Android package) files in a folder and I want to extract the manifest files from each of them. I am using Android apktool to convert them and since there are many APK files I want to convert them in a loop, not one by one.
apktool d hello.apk ./hello is the command for extracting manifest files from hello.apk and produces the output folder named hello.
I tried the command in the command prompt using for loop in the current directory in which all APK files are stored:
for \r %v in (*.apk) do apktool d "%v" "./%v".
I want the output folder of same name for each APK file, i.e. if APK is hello.apk the output folder should be hello. The above command is producing an error: cannot generate the output folder. How can I extract manifest files from all such APK files at once from a loop?
Maybe you forgot -o parameter?
That command works fine for me:
for /r %v in (*.apk) do apktool.jar d "%v" -o "./%~Nv"

Gradle Multi String Value files

from this link i had use multi language support in my Android Project, Yesterday i decided to switch to Intellij Idea gradle, when i remove value files in different language, app run normally with default language
but with multi string value file get this error
Error:Gradle: Execution failed for task ':...:processDebugResources'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/.../sdk/build-tools/android-4.4.2/aapt package -f --no-crunch -I
/home/.../sdk/platforms/android-19/android.jar -M
/home/.../.../build/manifests/debug/AndroidManifest.xml -S
/home/.../.../build/res/all/debug -A
/home/.../.../build/assets/debug -m -J /home/.../.../build/source/r/debug -F
/home/.../.../build/libs/...-debug.ap_ --debug-mode --custom-package ... --output-text-symbols /home/.../build/symbols/debug
Error Code:
1
Output:
/home/.../build/res/all/debug/values-Ar/values.xml: error: Duplicate file.
/home/.../build/res/all/debug/values/values.xml: Original is here.
Your problem seems to be with naming conventions.
The main problem with the structure you're using is that you used a capital letter.
In android file structure in res folder should always be in lowercase.
instead of
values-Ar
you should use
values-ar
for your values folder if you want an arabic locale to find your strings,values ...

XAPK File Validation Failed - APK Expansion Files

I am using the expansion files demo given in the sdks and am placing the obb file on the SD Card at the following location:
/Android/obb/package-name/package-name/main.versioncode.package-name.obb
But i get the following error:
XAPK File Validation Failed
For generating the .obb files this is the procedure i have followed :
1) copy all the images to a folder named main.versioncode.package-name.obb and then zip that file.
2) remove .zip file extension and place it in this /Android/obb/package-name/myobbfile.obb
Is this the correct way of doing it?
An OBB file is an uncompressed ZIP file, so make sure that you zip it without compression.
Every ZIP utility should have some sort of compression level option.
The following screenshot is the open source 7-ZIP gui for Add to Archive with a highlight i added to show where the Compression Level is set to Store.
Another way of doing it would be using jobb
Usage
The syntax for running jobb is as follows:
jobb [-d <directory>][-o <filename>][-pn <package>][-pv <version>] \
[-k <key>][-ov][-dump <filename>][-v][-about]
You can use the jobb tool to create an OBB file or extract the contents of an existing OBB. The following example command creates an OBB file from source files.
$ jobb -d /temp/assets/ -o my-app-assets.obb -k secret-key -pn com.my.app.package -pv 11
This example shows how to dump (extract) the contents of an existing OBB file:
$ jobb -d /temp/obb-output/ -o my-app-assets.obb -k secret-key
Here is how you need to get it done
1) You can put your images in any custom named folder you want. e.g myimages.
2) put all those images in a zip archive, once done adding rename that archive to main.versioncode.package-name.obb
3) Place that .obb file in directory sdcar/Android/obb/package-name/main.versioncode.package-name.obb
Hope it helps

how to generate apk file using a 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.

convert odex file to dex file

I would like to covert odex file to dex file. I already pulled framework folder from system. I tried the following command,
java -jar baksmali-2.1.2.jar -d system/framework -x temp.odex
but error was produced - error message is like below.
Error occurred while loading boot class path files. Aborting. org.jf.util.ExceptionWithContext: Cannot locate boot class path file /system/framework/core.jar
at org.jf.dexlib2.analysis.ClassPath.loadClassPathEntry(ClassPath.java:277)
at org.jf.dexlib2.analysis.ClassPath.fromClassPath(ClassPath.java:182)
at org.jf.baksmali.baksmali.disassembleDexFile(baksmali.java:67)
at org.jf.baksmali.main.run(main.java:113)
at org.jf.baksmali.main.main(main.java:322)
I could not find "core.jar" in my android system framework folder.
As of 2017-06-09 baksmali has changed. It works like this.
java -jar baksmali-2.2.0.jar d SamsungInCallUI.odex -o SamsungInCallUI
Then assemble the dex file.
java -jar smali-2.2.0.jar ass SamsungInCallUI -o SamsungInCallUI.dex
Try this instead:
java -jar baksmali-2.1.2.jar -c boot.oat -d system/framework/arm/boot.oat -x temp.odex
The specific path to your boot.oat might be different.
Also note that baksmali doesn't yet support deodexing the N preview images.
This worked for me adb pull /system/framework/arm/boot.oat /tmp/framework/boot.oat Placing the apk and the odex file baksmali.jar -x -c boot.oat -d /tmp/framework APKname.odex -o APKname
I'm not sure that I've understood correctly your question (kindly correct me if I'm wrong), but if you are trying to convert an odex to dex, I've already replied to a similar question here: https://reverseengineering.stackexchange.com/questions/12393/reverse-engineering-android-vendor-system-apps/12406#12406
Anyway, to my knowledge you have two chooice:
Follow this guide: http://www.naldotech.com/how-to-deodex-applications-on-android-5-0-lollipop/
Or use oat2dex as pointed out by the user who commented my answer on RE stackexchange.
Good luck
This is an extension of #kakopappa's answer.
Get the latest version of baksmali and smali jar from here and put them in a folder and add this method to your .bash_profile file if you are a mac/linux user.
Get baksmali and smali jar in your computer and assign it to these variables from terminal.
BAKSMALI_JAR_PATH = ""
SMALI_JAR_PATH=""
Note : After editing the value should look something like
BAKSMALI_JAR_PATH = "/Users/rabbit/tools/baksmali-2.2.7.jar"
SMALI_JAR_PATH = "/Users/rabbit/tools/smali-2.2.7.jar"
Copy paste this script in your terminal and restart your terminal. This is a shortcut function which would get added to .bash_profile and you would get it handy.
echo "BAKSMALI_JAR_PATH="$BAKSMALI_JAR_PATH >> ~/.bash_profile
echo "SMALI_JAR_PATH="$SMALI_JAR_PATH >> ~/.bash_profile
echo >>
function odextodex() {
odex_file_name=$1
deassembled_file=${odex_file_name%.odex}
java -jar $BAKSMALI_JAR_PATH d $1 -o $deassembled_file
java -jar $SMALI_JAR_PATH ass $deassembled_file -o $deassembled_file.dex
rm -rf $deassembled_file
}
After doing this type odextodex filename.odex - you should see filename.jar file in your current directory.

Categories

Resources