Renaming Android app package causes gradle crash - android

I'm trying to change the package name of my app but I'm seeing this gradle crash when building.
What went wrong:
Execution failed for task ':main:MyApp:processDebugResources'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/19.0.3/aapt package -f --no-crunch -I /Applications/Android Studio.app/sdk/platforms/android-19/android.jar -M /Users//Documents/workspace/android/application/main/MyApp/build/manifests/debug/AndroidManifest.xml -S /Users//Documents/workspace/android/application/main/MyApp/build/res/all/debug -A /Users//Documents/workspace/android/application/main/MyApp/build/assets/debug -m -J /Users//Documents/workspace/android/application/main/MyApp/build/source/r/debug -F /Users//Documents/workspace/android/application/main/MyApp/build/libs/MyApp-debug.ap_ -G /Users//Documents/workspace/android/application/main/MyApp/build/proguard/debug/aapt_rules.txt --debug-mode --custom-package com.app.myapp --output-text-symbols /Users//Documents/workspace/android/application/main/MyApp/build/symbols/debug
Error Code:
138

Correct way to change package name is
1) Go to manifest click on package="packagename" and press Shift+F6. Do refactor with all changes in all .
2) Click Do refactor in build config if that turns up
3) Go to package in src/main/java
4) Right click -> refactor -> move and click move to another package. Choose name and target directory.
5) It will create new package with files.
6) Delete old empty package
7) Clean project, restart android studio and clean once again
8) If you go to build/generated/source/r/debug you will see package name has changed.

Related

How to fix cp issue during build with ninja?

I am currently compiling a custom recovery for an android phone. Sources are synced, device tree etc. all set up correctly. Now I am facing a rather banal-looking error during build. cp refuses to copy a directory, because -r is not specified in the build file.
I obviously tried to find the build file (rw_recovery/out/build_omni_daisy.ninja) and add the -r argument, but it seems to be regenerated at the beginning of every build process, as the process still fails and the previously changed line appears unchanged when opening the file after the attempted build.
These are the build steps:
. build/envsetup.sh
lunch omni_daisy-eng #config for the device
mka bootimage #device uses boot.img as recovery
This command leaves me with the following error:
[ 99% 6883/6884] Prebuilt (rw_recovery/out/target/product/daisy/kernel)
FAILED: rw_recovery/out/target/product/daisy/kernel
/bin/bash -c "(rm -f /home/luca/rw_recovery/out/target/product/daisy/kernel) && (cp rw_recovery/out/target/product/daisy/obj/KERNEL_OBJ/arch/arm64/boot/ rw_recovery/out/target/product/daisy/kernel )"
cp: -r not specified; omitting directory 'rw_recovery/out/target/product/daisy/obj/KERNEL_OBJ/arch/arm64/boot/'
ninja: build stopped: subcommand failed.
17:13:06 ninja failed with: exit status 1
I would love to hear any suggestions about how to force ninja to execute the command with -r. Alternatively, suggestions about where to find the file from which the above mentioned build file is recreated after executing mka command are much welcomed as well.

Maven Android build error

My Maven based project is executing the following command resulting in the error that follows:
Command
/bin/sh -c cd /Users/conor/Repositories/Dev/MyPosLogger/samples/HelloMyPosLogger && /Users/conor/Library/Android/sdk/build-tools/22.0.1/aapt package -f --no-crunch -I /Users/conor/Library/Android/sdk/platforms/android-19/android.jar -M /Users/conor/Repositories/Dev/MyPosLogger/samples/HelloMyPosLogger/target/filtered-manifest/AndroidManifest.xml -S /Users/conor/Repositories/Dev/MyPosLogger/samples/HelloMyPosLogger/src/main/res -S /Users/conor/Repositories/Dev/MyPosLogger/samples/HelloMyPosLogger/target/unpacked-libs/android.support_compatibility-v7-appcompat_apklib_22.0.0/res -m -J /Users/conor/Repositories/Dev/MyPosLogger/samples/HelloMyPosLogger/target/generated-sources/r --output-text-symbols /Users/conor/Repositories/Dev/MyPosLogger/samples/HelloMyPosLogger/target --auto-add-overlay
Error
/Users/conor/Repositories/Dev/MyPosLogger/samples/HelloMyPosLogger/target/unpacked-libs/android.support_compatibility-v7-appcompat_apklib_22.0.0/res/values-v21/styles_base.xml:75: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.
Why is this and how do I fix it please?
I am using Android Maven Plugin v3.8.2
I have faced this error before and i solved it by the followin
Open Android sdk and make sure latest version of support library is installed or not. If not then install it also check compile pi version for your project is latest or not i.e. 21.
2.After installing just mvn clean install.
This will solve the issue.

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 ...

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.

Resolve error while loading 'dexed' JAR on Android

I'm trying to make a bundle for Felix on Android which may take photos regularly.
All the code compiles well and it can be resolved by Felix, but when I try to start it, I get an exception (java.lang.VerifyError) and this trace in logcat :
I/dalvikvm( 738): Failed resolving Lbarcode/android/CameraHandler; interface 1 'Landroid/hardware/Camera$PictureCallback;'
W/dalvikvm( 738): Link of class 'Lbarcode/android/CameraHandler;' failed
E/dalvikvm( 738): ERROR: defineClass(0x40093110, barcode.android.CameraHandler, 0x400c93b8, 0, 1769, 0x40204708)
The CameraHandler class opens a Camera object, and implements PictureCallback and AutoFocusCallback.
The .jar file has been 'dexed', via a simple 'dx --dex --output=classes.dex ... && aapt add ... classes.dex'.
I don't know why this error raise, so if someone has a solution...
Thanks
It appears that you've omitted some necessary classes as arguments to dx.
You'll have more success if you use either Android's Eclipse plug-in or the create project action in the android commandline tool. Each of these take care of running the right tools in the right order to build an Android apk to spec.
$ ~/android-sdk/tools/android --help
Usage:
android [global options] action [action options]
...
Action "create project":
Creates a new Android Project.
Options:
-n --name Project name
-t --target Target id of the new project [required]
-p --path Location path of new project [required]
-k --package Package name [required]
-a --activity Activity name [required]

Categories

Resources