Beginning of the story
A draft written on cocos2d came to me for revision. A game for children in which you need to collect puzzles and learn words. Work as work, but the main problem was that before me a certain girl from India worked on the project. And then I started a very fun period. An example of what I had to look at, what to do and how it all ended will be under the cut.
Indocode provides mood for the whole day. However, the post is not about errors that I had to fix, but quite about another problem.
After several months of work on the project, when the main problems were solved, the customer asked to build a build for his Android device. Then there was an amazing conversation about the fact that the first developer had to write for cocos2d-x and the application should run easily on any device. I had to solve the problem and my choice fell on Apportable.
')
Actually the topic
According to the official website, Apportable SDK is a system that allows you to run the same xCode project on iOS and Android devices. First of all, it concerns the games written on cocos2d. C porting some system Core frameworks has problems.
Our game was written practically on a pure coconut and only in two places UIKit elements were used.
Well then. Let's get started
The first thing to do is install the SDK on a Mac. To do this, following the instructions on the site, you just need to enter in the terminal
(echo; echo PATH=~/.apportable/SDK/bin:$PATH) >> ~/.bash_profile; source ~/.bash_profile
The SDK requires about 2GB of free disk space and xCode 5 installed.
While all this is being downloaded, the necessary code can be added to our project.
First, set the screen emulation mode. There are several options.
For example:
UIScreenIPhone3GEmulationMode - used if your application does not support graphics from retina devices. The size of the virtual screen 320px / 480px, scale - 1.0
UIScreenScaledAspectFitEmulationMode - stretches your application in accordance with the screen size of the Android device. Uses non-retina graphics.
UIScreenBestEmulatedMode - stretches your application in accordance with the screen size of the Android device. Uses the most appropriate graphics. For this mode to work correctly, there must be graphics for all variants of iPhone and iPad screens. Otherwise, it may not look the best.
int main(int argc, char *argv[]) { @autoreleasepool { #ifdef ANDROID [UIScreen mainScreen].currentMode = [UIScreenMode emulatedMode:UIScreenAspectFitEmulationMode]; #endif int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); return retVal; } }
All options typedef NS_ENUM(NSUInteger, UIScreenEmulationMode) { UIScreenIPhone3GEmulationMode, UIScreenIPhone4EmulationMode, UIScreenIPhone5EmulationMode, UIScreenIPadEmulationMode, UIScreenIPadRetinaEmulationMode, UIScreenAspectFitEmulationMode, UIScreenScaledAspectFitEmulationMode, UIScreenBestEmulationMode, UIScreenBestEmulatedMode = UIScreenBestEmulationMode, UIScreenNativeMode, UIScreenNativeRetinaMode, UIScreenBestNativeMode, };
The next thing that had to be redone was the position of the elements.
[item setPosition:ccp(400, 600)];
on
[item setPosition:ccp(puzzle.contentSize.width * 0.2, puzzle.contentSize.height * 0.772)];
The same when tracking clicks.
After this, go to the project folder in the terminal and enter:
apportable load
This command will create an apk file, download it to a connected device, install and launch it. Ideally. He is not always. I will not consider file link errors, they are very individual. However, there is a situation when the apportable does not see any particular device. At the office of 7 devices on which I tested the application, I could not install on 3.
What to do in this case? Everything is very simple. Apportable first creates an apk file and only then tries to download it to the device. So this file is somewhere there. More specifically, here it is:
/Users/username/.apportable/SDK/Build/android-armeabi-debug/ProjectName
In this folder is an apk file and you can simply transfer it to the device and install it. For this, I used the Android File Transfer application (in the poppy out of the box you cannot access the memory of Android devices).
Everything? Profit? Unfortunately not.
There was a problem with the camera. The camera was called, took a photo, but when you clicked the confirmation button, the application fell. The problem was not googled and promised to bring big problems, but ... Help came from our android developers. I learned what the manifesto and the permisena are.
What is this? For iOS developersAnalogue of our info.plist. The manifest contains the basic settings, all rights and configuration.
So. After creating the build using apportable, a folder ProjectName.aproj appeared in the project directory. In this folder are configuration files and files that are not compiled (for example, resources).
We are interested in the configuration.json file. In it, you can change the project's compilation settings for android. For example, add permisheny. For the camera need the rights to record.
And row change
"FEATURES": ["opengles2","landscape"]
on
"FEATURES": ["opengles2","landscape","write_external_storage"]
magically solved the problem.
There is also a nuance with the localization of the application name on the device screen. For each language, you must add the file
strings.xml and put it in the folder ProjectName / java / res / values- [lang_description]
strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Localization name</string> </resources>
And add in configuration.json:
A few points to last:
- There are a lot of screen ramer on Android devices, and in some places you had to use the following inserts:
Hidden text #ifdef ANDROID CGRect frame = [UIScreen mainScreen].applicationFrame;//1.7031 - pad 1.778 - phone CGFloat ratio = frame.size.height / frame.size.width; if (ratio < 1.72) { x = 16; } else{ x = 29; } #endif
- If the “portrait” flag is not in the configuration.json file, and the Device Orientation in the xCode settings of the project is checked against “Portrait”, then portrait orientation will be supported. Be careful.
- Official docs.apportable.com documentation
- In Apportable many system frameworks are added. Official documentation contains little information about this. New .h files with new methods available for android can be viewed in the folder
/Users/username/.apportable/SDK/sysroot/System/Library