I need to lock the screen to a specific orientation for an android app that I'm making.
is there a way to do that in QML? Google didn't get me any answers.
I am using Qt 5.2.
You can basically use the Screen.orientation property for reading only. See the following example for details:
http://qt-project.org/doc/qt-5/qtquick-window-screeninfo-qml.html
The proper way as of today is to use the Android manifest file for this as done by the Qt Android developer at Digia for his QtHangMan game which is:
<activity android:screenOrientation="portrait" ...
The way to do this is-
Create an out-of-source directory - let's call it "templates" (can be anything)
Copy the AndroidManifest.xml into "templates" from -
<path to qt installation>/android_armv7/src/android/templates/AndroidManifest.xml
Edit the copied AndroidManifext.xml with your favorite editor and change the orientation from "unspecified" to "sensorLandscape" (or anything else you prefer) and save the file.
In the qmake file (*.pro) of your project, add the following line -
ANDROID_PACKAGE_SOURCE_DIR = <path to your templates directory> #in case you added the directory one above the source directory, path to your templates directory = "../templates"
Build and Run. You should now see that the Orientation is fixed to whatever you have specified in the custom AndroidManifest.xml file
To understand what really is happening - here's the qt reference, look for ANDROID_PACKAGE_SOURCE_DIR
In case the link doesn't work in future, here's the relevant bits -
"ANDROID_PACKAGE_SOURCE_DIR: This variable can be used to specify a
directory where additions and modifications can be made to the default
Android package template. The androiddeployqt tool will copy the
application template from Qt into the build directory, and then it
will copy the contents of the ANDROID_PACKAGE_SOURCE_DIR on top of
this, overwriting any existing files. The update step where parts of
the source files are modified automatically to reflect your other
settings is then run on the resulting merged package. If you, for
instance, want to make a custom AndroidManifest.xml for your
application, then place this directly into the folder specified in
this variable. You can also add custom Java files in
ANDROID_PACKAGE_SOURCE_DIR/src."
QtCreator - 4.2.1, Qt - 5.8
Related
I'm using Qt 'qmake' from the command line (no use of QtCreator) am building for an Android target. No matter what I do it seems to use Android API level 9 in the Makefile it generates. Is there a command-line option, environment variable, or other method I can use to tell qmake to use a specific Android API level. I've been searching for a long time and cannot find anything.
Change environment to ANDROID_NDK_PLATFORM=android- the api-level you want or in QtCreator->Project->Build Environment->Add/update the above variable.
To choose a specific minimum API level, you need to provide your own Android manifest file.
I know you're not using Qt Creator, but it supports this by being able to generate a new manifest file from a template.
More details available from the Qt Docs on deploying to Android:
http://doc.qt.io/qtcreator/creator-deploying-android.html
You can specify settings for the androiddeployqt tool in Qt Creator and in the project .pro file. To specify settings in Qt Creator, select Projects > Build Android APK > Details.
...
You can use the qmake variables to specify all the settings you need for the androiddeployqt tool and you do not need an Android manifest file until you want to publish the package in an application store. To specify additional settings for APK packages, you can create an Android manifest file and edit it in Qt Creator. Select Create Templates to create the file and to open it in the Android Manifest Editor.
If you're not using Qt Creator you'll presumably need to generate an Android manifest file manually and place it in your source directory. androiddeployqt should pick it up.
ANDROID_PACKAGE_SOURCE_DIR: This variable can be used to specify a directory where additions and modifications can be made to the default Android package template. The androiddeployqt tool will copy the application template from Qt into the build directory, and then it will copy the contents of the ANDROID_PACKAGE_SOURCE_DIR on top of this, overwriting any existing files.
...
If you, for instance, want to make a custom AndroidManifest.xml for your application, then place this directly into the folder specified in this variable.
...
Note: When adding custom versions of the build files (like strings.xml, libs.xml, AndroidManifest.xml, etc.) to your project, make sure you copy them from the package template, which is located in $QT/src/android/java. You should never copy any files from the build directory, as these files have been altered to match the current build settings.
I have Delphi XE5 without updates.
I might have missunderstood the way I should use the BAT file.
In the build.bat template plus the install.txt, my understanding leads me to think than I should use test_classes.dex to be merged with the original classes.dex that embarcadero provides, in order to run the demos correctly.
However, I am not intereseted in testing the demos. I would like just to use the components inside my own project.
Which files should I merge?
Thanks in advance for your guidance and help.
I found the solution here http://blog.blong.com/2013/11/delphi-and-android-services-part-2.html.
It says:
1) Review the build.bat file and ensure the environment variables are set
correctly:
2) ANDROID needs to point to your Android SDK base directory, e.g.
C:\Users\Public\Documents\RAD Studio\12.0
\PlatformSDKs\adt-bundle-windows-x86-20130522\sdk or
C:\Android\android-sdk-windows
3) ANDROID_PLATFORM needs to point at an installed SDK platform
installation, e.g. %ANDROID%\platforms\android-15 or %
ANDROID%\platforms\android-17. Check for one that is installed.
4) DX_LIB needs to point to the lib subdirectory under the Android SDK
build-tools directory, e.g. %ANDROID%\build- tools\18.0.1\lib or
%ANDROID%\build-tools\android-4.2.2\lib
5) EMBO_DEX needs to point to the Delphi-supplied Android classes.dex
file, wrapped in quotes to take care of any spaces in the path, e.g.
"C:\Program Files (x86)\Embarcadero\RAD
Studio\12.0\lib\android\debug\classes.dex"
6) Run build.bat
7) You should now have a new file in the project directory tree called
java\output\dex\classes.dex
This file replaces the supplied classes.dex and has the Java service
and broadcast receiver compiled classes included in it.
8) Set the new classes.dex for deployment
I have successfully created a project with the cordova command line tool and I am able to import this project in the Android Development Toolkit as well as run it in the emulator.
Now, I see the example files in the folder "/www". When I change these files, build the project (using CIT) and run it in the emulator, I do not see the changes I made. I assume that I need to change other files or put them in another folder. The assets folder is empty besides a file that says that I need to delete the exclusion filters to see the files. Do I need to change the files in there?
???
Thanks for any hint!
Once a cordova project has been created. It has a root /www folder where all resources are eligible to be shared on the added platforms (which you intends to add)
You should modify here. though its possible to modify resources per platform. (read more API)
Once any shared resource i.e. inside the main www folder are modified then you have to issue cordova build in order to reflect the changes in the corresponding platforms (which you have added)
You are unable to see the assets folder resources. Because by default it is hidden. Just select the project and go in properties and then remove the checks.
Import existing Android project --> select project --> right click select properties --> Resource --> Resource filters.
From the Exclude All , remove both items. This will show you resources inside assets folder.
I have created an AIR app that is currently on the market. To update the app, obviously I must keep the same package name. My first version's were packaged using Eclipse with the ADT plugin.
Now to use AIR 3.0 Native Extensions (ANE) which were not available when I first developed the app, I currently must create my APK using AIR's command line tools. Unfortunately, these command line tools force you to have a package name that starts with the word "air". For example, I need the package name "com.example". AIR creates the package name as "air.com.example".
So now, I cannot update my app in the market since the package name has changed. Adobe has this horrific article to help you rename and remove the "air" in the package. I'm not a great programmer so this has really stumped me.
http://kb2.adobe.com/cps/875/cpsid_87562.html
Apparently this info is out of date or incorrect in a few areas.
I have completely stumbled at step 12 which uses apkbuilder:
apkbuilder final.apk -u -z resources.arsc -f classes.dex
I am getting this error message:
THIS TOOL IS DEPRECATED. See --help for more information.
java.io.FileNotFoundException: resources.arsc does not exist
I have used step 10 to create the new resources.arsc file. It clearly DOES exist and in the correct location. I tried using apkbuilder with other resources.arsc files taken from other projects. I still get the same error message.
Is there a chance in hell of this working? If anyone is interested in this, I have a zip file with a sample AIR apk, windows bat files for all the command line work, and all the needed utilities so they don't need to be downloaded. To get started you just need to change my path.bat to fit your system. And you need notepad++ (or an equivalent) to batch automate renaming the package name across several files.
bradwallacedesign.com/dktimer/renameApkProject.zip
Thanks so much!
this was done on a pc. i have no idea how to do this on a mac.
i don't recommend using this to remove the "air." from an air package name. If you do so, the user will not be prompted to download air on their device. the user will get an error message instead with no clue to the problem. of course you can use air captive runtime to solve this issue.
http://bradwallacedesign.com/share/renameAPK.zip
download and unzip my file (renameAPK.zip) to c:\renameAPK.
required files:
my file (renameAPK.zip) which contains the apkTool
java jdk/jre
android SDK
notepad++ (or an equivalent text editor that can rename across multiple files)
i made many bat files since i'm not sure how to combine them into one file. you will need to edit each one to change your path names and file names to work with your computer and your apk file.
i numbered all the bats in the order that i use them. once a command line is open, i type the number of the bat file i want then hit the tab key to automatically finish the name of the bat file then hit enter to run that bat file.
instructions:
double click `openCmd.bat to open a command line pointing to the directory with all your files.
0. run 0path.bat to set your path. (i can't remember now if the adobe air sdk is needed for this but i have it in my path. obviously, the JDK is needed and the android sdk for the jarsigner and zip align i think.)
1. run 1decompileAPK.bat to have apkTool decompile your app into a folder called UNZIPPEDapk
2. follow the instructions in 2editManifest & PackageName - Instructions (not a bat).txt to edit the manifest and package name using Notepad++ inside UNZIPPEDapk:
edit AndroidManifest.xml:
a. change package name from air.oldPackageName to newPackageName
b. edit other needed entries:
c. rename folder system inside "smali" folder so that it works with your new package name
for example:
if the old package name was: air/oldName then change the folders to match the new package name: air/newName
use notepad++ (or any editor that can find and replace text over many files)
d. ctrl+shift+f --- "Find in files"
find:
air/oldPackageName
replace with:
newPackageName
where:
all files in UNZIPPEDapk/smali
(i think there were over 200 replacements)
3. run 3buildDistFolder.bat to have apkTool build the new apk in the UNZIPPEDapk\Dist folder
4. follow the instructions in 4getMissingFiles - instructions.txt to reinstate the 2 missing files in the new build:
a. Two files were not built during 3buildDistFolder:
3buildDistFolder.bat built the new apk in the \UNZIPPEDapk\dist folder but it failed to copy 2 files:
(skipping hidden file 'C:\Users\computer\apkTool\UNZIPPEDapk\assets\META-INF
\AIR\extensions\com.adobe.mobile\META-INF\ANE\Android-ARM.classpath')
(skipping hidden file 'C:\Users\computer\apkTool\UNZIPPEDapk\assets\META-INF
\AIR\extensions\com.adobe.mobile\META-INF\ANE\Android-ARM.project')
grab these 2 files from your original apk and drop them into your new apk in the correct folder
b. copy yourApp.apk from DKTimer/Dist/ to root directory where your bat files are.
5. run 5signAPK.bat to sign the apk.
developer.android.com/guide/publishing/app-signing.html
6. run 6verifySigned.bat to verify the signing worked properly
7. run 7zipAlign.bat to align the apk file.
developer.android.com/guide/developing/tools/zipalign.html
You are finished at this point. Continue on if you want to test it on a device.
8. run 8installAPK.bat to install the apk on a usb connected device.
9. run 9remoteDebugger.bat if you want to use remote debugging.
i hope this helps someone. let me know if i forgot to include something.
also, if you know a better way to do this, please comment (such as how to combine this into 1 long pausing bat file...)
There is a simple environment variable you can set to disable the air. prefix easily. The following code exists in the Adobe AIR packager:
String optOut = System.getenv("AIR_NOANDROIDFLAIR");
if ((optOut == null) || (optOut.indexOf("true") == -1)) {
packageName = "air." + packageName;
}
So, simply set the AIR_NOANDROIDFLAIR environment variable to true, repackage your application, and it won't have the air. prefix. Google how to set environment variables in windows or mac for your particular OS version.
For example, I use the command-line compiler on Mac/Linux, so I run:
> export AIR_NOANDROIDFLAIR=true
> java -jar $AIR_HOME/lib/adt.jar -package -target apk-captive-runtime -storetype pkcs12 -keystore cert.p12 -storepass *** Main.apk Main-app.xml Main.swf
Warning: I don't know what implications this has. Per someone's note above, this may only be a good idea with captive runtime (but that's the default going forward from AIR 3.8).
Update: Renaun Erickson said it shouldn't cause problems.
Cross-posted here (slightly different question, same answer).
Having tried several apkRename tools, I found that they all failed for some app, such as com.android.browser on HTC device.
The reason is in apktool which does not correctly unpack apk file sometimes.
So, i create my own tool: https://github.com/sjitech/ApkRename
No need apktool, no need aapt, just java and jar utilities.
This utility directly modify AndroidManifest.xml so without recompile whole resource by apktool,
so it's clean.
Tested devices: 11 kinds (both android 4+, but 2.2+ should be no OK)
Tested OS: Mac OS X 10.9 and CentOS 6. (Cygwin with bash 4+ should be OK, but not tested yet)
I actually tried brad's approach and couldn't imagine having to go through the process EVERY TIME i compiled a release. so i did something else...i modified ADT so it doesn't insert "air." at the start and replaces it with a more useful extension like "com."
Here's a summary of the approach:
use:
jar xf adt.jar
to extract the adt.jar file to a directory on your desktop. you'll find it in {adobe SDK}/lib/
look for the file APKOutputStream.class
com/adobe/air/apk/APKOutputStream.class
Open it in a hex editor (eg, HxD is what i used). Search for "air." (without the quotes but including the dot).
Don't delete the entry. i tried, you can't, it corrupts the class and it won't run. What you can do, however, is replace "air." with "com." because it has the same number of characters and doesn't mess with the length of the file. The com prefix is a lot more useful to most of us.
save the modified APKOutputStream.class file and repackage with JAR. something like this:
jar cfm ..\patchedadt.jar ..\MANIFEST.MF *
you'll want to copy that MANIFEST.MF file from the subdirectory of the package called META-INF
Rename your patchedadt.jar to adt.jar and put it back in the lib directory. Works with the Flash Builder and all that garb.
Needless to say, when you're in there, you'll want to produce your package without a "com." prefix so you don't end up with com.com.your.package.name.
maybe there was an easier way, but i didn't know any better and no one else had an answer except to decompile the apk, modify it, and recompile and that didn't even work. so i figured i'll share what i did in case someone else stumbles on it later :)
jim
I'm building AOSP from source. What I would like to do is to include a few prebuilt files in the generated system.img as part of the make process. I'm trying to find the actual file that creates the system.img and add a few lines there. Any idea?
Thank you in advance.
A good way of adding custom files to the system.img is to add them under vendor/your_name/product_you_want_to_add_them/proprietary/your_files_go_here and add a custom make file called device-product_name.mk.
After that's done, just define which files are to be copied from the proprietary folder and inside (e.g. vendor/samsung/crespo/device-vendor.mk add to call your device make file).
Just put your source code to the Packages/apps directory,then make sure your project has a correct make file like other project in the apps directory.You will make the package prebuilt after finish the android build.
To add a prebuilt file to a build, find a .mk file which makes sense for your project and add the file under PRODUCT_COPY_FILE. It looks like this
PRODUCT_COPY_FILE += your/build/tree/$FILE:path/to/location/on/device/$FILE
Using a separate vendor tree is following good domain-driven principles...but is perhaps overkill for a single binary. Examine the makefiles you already use, there is often prebuilt apks already being added that you can piggyback on. device and existing vendor trees are good places to start looking. Maintaining an entirely new project is not something to be taken lightly, in my opinion.
If you want to add programs in the system.img, go to the vendor, then go to the operator, then go the app and enter the files inside the app
If you use the roms modification program, the program name is rom helper, it modifies prmission to 0755, and it modifies UserID 2000, thus adding the apk to rom