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.
Related
I want to reduce Android Studio project size to save it for after use
In MS Visual Studio, we can delete *.ipch, *.sdf and Debug files to reduce the project size
I see app/build/intermediates folder is really large, can I delete this folder?
Yes, you can safely delete the intermediates folder. You can even delete the whole build folder that contains intermediates.
The build folder and it's contents will be re-generated the next time you run/build your project though.
In Android Studio, go to the Terminal window. If you did not go to a different directory since you opened the IDE, you should find yourself on the top level of your project folder (something like ../Android Studio/projectname). There you simply type
./gradlew clean
That's it. I just reduced my project folder size from 589 MB to 21 MB.
The file .gitignore containted in the project created by AndroidStudio lists all files / patterns not to be stored in the git repository, i.e. those files that are not required for building the project. Therefore, it should be safe to remove all files / directories matching the patterns listed in the .gitignore file.
In my projects it lists:
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
Please find the batch file I use to do that.
Set the batch under the root of your project directories.
Hoping it helps.
#rem ##########################################################################
#rem
#rem Export an ANDROID STUDIO application
#rem
#rem ##########################################################################
echo off
CLS
echo _________________________________________
echo ANDROID-STUDIO files sources export
echo _________________________________________
echo
echo If directory name includes space
echo - Surround name with quotes
echo _________________________________________
set /p dirname= Dir name to export :
if %dirname% == "" goto ERROR
set str=%dirname%
mkdir c:\EXPORT\%str%
pause
xcopy %dirname% c:\EXPORT\%str% /s
del c:\EXPORT\%str%\*.iml
del c:\EXPORT\%str%\app\*.apk
rmdir c:\EXPORT\%str%\.gradle /s /q
rmdir c:\EXPORT\%str%\.idea /s /q
rmdir c:\EXPORT\%str%\build /s /q
erase c:\EXPORT\%str%\app\build /f /s /q
rmdir c:\EXPORT\%str%\app\build /s /q
pause
goto END
:ERROR
echo Cannot create, check the directory root
goto OUT
:END
CLS
echo _________________________________________
echo ANDROID-STUDIO EXPORT
echo _________________________________________
echo Export ended, check c:\EXPORT
:OUT
pause
In Android Studio:
Click on Graddle >> app >> build >> and double click on "clean"
Mac & Linux users:
In terminal type ./gradlew clean in the root of your android project.
Windows users:
In cmd paste gradlew clean in the root of your android project.
I'm trying apk tool, following the instruction I have create a folder with
Where
-myapp.apk is a sample app that I want to decompile
My bat Decompile.bat is
#echo off
pushd "%~dp0"
apktool if myapp.apk
apktool if framework-res.apk
apktool d myapp.apk
pause
When I start the bat the prompt autoclose after the first lines execution
#echo off
apktool if myapp.apk
apktool if framework-res.apk
the execution of these line is correctly but jump the latet line for some reason
If I try to use apktool from prompt works, so the problem is my bat file but I don't know how to fix it
You need to see how apktool.bat is referencing java. I downloaded the source from github and this is what's listed:
#echo off
set PATH=%CD%;%PATH%;
java -jar "%~dp0\apktool.jar" %1 %2 %3 %4 %5 %6 %7 %8 %9
If that's the case then it's assuming that java is in the PATH variable or in the current directory. Maybe add an echo for the path and see why it cannot find it. Alternatively, set the JAVA_HOME environment variable and put the full path to java inside of apktool.bat.
I'm trying to sign an APK with SignApk, but I keep getting this error:
Error: Unable to access jarfile signapk.jar
I have appended my JDK directory as well as my SignAPK directory to my system path variable. The java command works fine through the command-line, but I can't seem to get the -jar option to work correctly for signing APKs.
My SignApk folder is located on my C:\ drive, so it looks like this:
Here is what I am trying to do through the command-line:
Please ignore the blank space in between the variables as I was trying to cover up my details. The syntax that I am using is:
java -jar signapk.jar certificate.pem key.pk8 myapk.apk myapk-signed.apk
I have tried the commands from the SignApk directory as well as the bin directory inside of that directory. Can anyone help me troubleshoot how to resolve this issue? Thanks
As you might notice, there is no signapk.jar file there, there is only signapk without extension.
Download different SignApk from here:
http://www.mediafire.com/download/h5fob1afzt1p4ss/SignApk.rar
Password: SanketN8
just download Signapk.zip and unzip wherever you wish, paste your apk inside the signapk folder.
open cmd / terminal , change directory to signapk
java -jar signapk.jar testkey.x509.pem testkey.pk8 test.apk test-signed.apk
copy and replace with you existing file name (test.apk) and output file (test-signed.apk )
signapk.zip - https://drive.google.com/open?id=0ByAytNiwJoUaQ3NvVzlPX0xGUFU
image
In case one encounters this message when signing a LineageOS build:
Get rid of ./build/tools/releasetools/ prepended to (old) commands used for signing.
See https://wiki.lineageos.org/signing_builds#:~:text=For%20LineageOS%20versions-,older%20than,-18.1%20you%20will
i am tryig to execute a sample python program through monkey runner command prompt and it is throwing an error
Can't open specified script file
Usage: monkeyrunner [options] SCRIPT_FILE
-s MonkeyServer IP Address.
-p MonkeyServer TCP Port.
-v MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO,
WARNING, SEVERE, OFF)
Exception in thread "main" java.lang.NullPointerException
so any one can guide me how to resolve this one
scriptfile should be a full path file name
try below
monkeyrunner c:\test_script\first.py
try using something like
...\tools>monkeyrunner -v ALL first.py
where first.py was my sample python script which I copied into tools folder of android SDK (the place where monkeyrunner.bat is located)
Under all unix/linux families OS the sha bang syntax can be used.
Edit the first line of your script with the results of the following command:
which monkeyrunner
for example, if monkeyrunner (usually provided with android sdk) has been installed under /usr/local/bin/sdk write:
#!/usr/local/bin/sdk/tools/monkeyrunner
or even use "env"
#!/usr/bin/env monkeyrunner
then set you script file as executable
chmod +x <script>
You can now launch your script from the shell.
It looks not make sense to switch working directory to Android SDK folder but just for obtain some relative references path for itself. It means you have to specify the full path for your script file and the PNG image files you want to save or compare to.
A better way is modify few lines in the "monkeyrunner.bat" under your SDK folder as below. This will use your current path as working directory, so, no necessary to use full path file name.
rem don't modify the caller's environment
setlocal
rem Set up prog to be the path of this script, including following symlinks,
rem and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0
rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
rem cd /d %~dp0
rem Check we have a valid Java.exe in the path.
set java_exe=
call %~sdp0\lib\find_java.bat
if not defined java_exe goto :EOF
set jarfile=monkeyrunner.jar
set frameworkdir=
set libdir=
if exist %frameworkdir%%jarfile% goto JarFileOk
set frameworkdir=%~sdp0\lib\
if exist %frameworkdir%%jarfile% goto JarFileOk
set frameworkdir=%~sdp0\..\framework\
:JarFileOk
set jarpath=%frameworkdir%%jarfile%
if not defined ANDROID_SWT goto QueryArch
set swt_path=%ANDROID_SWT%
goto SwtDone
:QueryArch
for /f %%a in ('%java_exe% -jar %frameworkdir%archquery.jar') do set swt_path=%frameworkdir%%%a
:SwtDone
if exist %swt_path% goto SetPath
echo SWT folder '%swt_path%' does not exist.
echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
exit /B
:SetPath
call %java_exe% -Xmx512m -Djava.ext.dirs=%frameworkdir%;%swt_path% -Dcom.android.monkeyrunner.bindir=%frameworkdir%\..\..\platform-tools\ -jar %jarpath% %*
I met the same things as you did, I resolved by using "monkeyrunner" command under tools, and your script file should be a full path name. It looks like the directory “tools” is the main directory of MonnkeyRunner. I am depressed that I can't run my script files by pydev IDE directly.
monkeyrunner.bat cygpath -w $(pwd)/monkey.py
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.