Friday, January 13, 2017

Android Build using Sencha

Step 1: Install/Verify you have Java 


              a. Run “java –version” on the command line.
              b. If the java –version doesn’t work then download the Java SDK (JDK and JRE) from
                   http://www.oracle.com/technetwork/java/javase/downloads/index.html
              c. Install the SDK.
              d. Set the environment variable JAVA_HOME = “C:\Program Files\Java\jdk1.8.0_91” (example).
              e. Add “%JAVA_HOME%\bin” to your “path” variable.
               f. Run java –version again which should now give you the Java Version.

Step 2: Install/Verify Android SDK platform

               a. Run “android list platform” in the command line.
               b. If you get something as “unrecognized” then you probably don’t have android SDK installed or you don’t have the “android sdk” not set in “environment variable”.
                c. Installing “Android SDK”
                Install “installer_r24.4.1-windows.exe” from https://developer.android.com/studio/index.html
                Set “ANDROID_HOME” variable in System Variables to
                C:\Softwares\Android\android-sdk (example).
                Set these paths in the “path variable”: C:\Users\svegiraj\AppData\Local\Android\sdk\platform-tools\;C:\Users\svegiraj\AppData\Local\Android\sdk\tools\ (example).
                 Also set “path variable” to “%ANDROID_HOME%\tools” (example).
                d. Now run “android list platforms” again. It should run.
                e. Install “android-22”, “HAX-Machine” for emulator and “Atom Processor”. These are mandatory and others might include depending on the requirement.
                f. If you want to run the emulator using proxy then you might have to run the following command
 “emulator –avd {emulator name} –http-proxy http://username:password@proxy.ihc.com:8080”.
Step 3: Do a sencha app build native
              a. There might be some proxy issues if you’re doing the build using the organization network. You might want to use a personal hotspot.
              b. There might some problems which might occur during this build.
1. Connection Refused:  This happens due to the proxy issues which will get resolved if you connect to a personal hotspot.
2. You will also need to install a whitelist plugin and once you do that the build might throw up an error like error in “url.” In the InAppBrowser plugin.
3. This is because the InAppBrowser plugin being used is of Old Version. You will have to remove the old InAppBrowser plugin and install the latest version.
4. You will also need to comment the push plugin and inappbrowser plugin url in the hookscripts folder of ihclib and cordova so that you don’t again install the same version or plugin.
5. And now when you do the sencha app build native it should run.

Step 4: You might need to change the URL in the BASE_URL in APPSETTINGS and give an ip address in the place of lpvecisdev203 as it might not connect to the specified url.

Step 5: Do a Sencha app build native again and then cordova emulate android to run the app on the emulator.

The above steps will help you get the Android application running.
Major errors once the Android Build gets ready
There was this Cookie issue we were facing Android. The cookie which we set was not going in the actual network but it was being replaced by some other one.
If you have one, you can clearly know that by printing the oAuth2Cookie you are actually sending in the Sencha Architect and seeing the actually cookie that is going in the Google or Safari’s developers console (Network tab).
 To resolve the issue you need to use Cookie Master.
Steps to use Cookie Master:
Step 1: Make sure you have the Cookie Master Plugin.
Step 2: In the place where you are setting the cookie you need to do the following:
  
1)      Let’s say this is your cookie :

AMWEBJCT!%2Fmga!JSESSIONID=00005GDpg7X6Ny4YhuUThzjSDQ9:b694bcfd-98c5-4b24-9875-a856ae40265a; Path=/; PD_STATEFUL_0c2a40bc-7a67-11e4-aa54-0050569d7a73=%2Fmga; Path=/; PD-S-SESSION-ID=1_2_1_YGjdoJ0XHo1YZAbotK-GDPyX4pX0NXNLFHlnma+05+a4TcQ+; Path=/; Secure
Step 1: Split the cookie into array using the “;” as a separator.
Step 2: Let’s say you get cookieArr from the above split.
Step 3: Again split the cookieArr using the “=” as a separator.
Step 4: You will get a cookieArrPair where you will have the key and value pair.
Step 5: Set the above in the cookie master as

                cookieMaster.setCookieValue(searchUrl, cookieArrPair[0], cookieArrPair[1]);
                cookieMaster.setCookieValue(searchUrl, cookieArrPair[4], cookieArrPair[5]);
                cookieMaster.setCookieValue(searchUrl, cookieArrPair[8], cookieArrPair[9]);
               searchUrl -> domain
               cookieArrPair[0] -> Key (J_Session or P_Session or P_Stateful)
               cookieArrPair[1] -> Value
Step 3: After this code, don’t set the cookie any more in the store. Comment that out.
Step 4: The above sub-steps may help you solve the cookie problem
Step 5: But, according to our tests this code doesn’t work for iOS. In the iOS you just need to set the cookie directly in the store.
            The below is a code example of how you might perform the above steps

//Step 1
var cookieArr = oAuth2Cookies.split(";");
var cookieArrPair=[];
//Here the cookieArrPair contains J_SessionID, P_SessionID, P_StatefulID
for(i=0;i<cookieArr.length-1;i++){
//Step 2
cookieArrPair = cookieArrPair.concat(cookieArr[i].split("="));
}
providerStore.setProperties({'url':searchUrl});

//Here we are setting the cookieMaster with the J_SessionId, P_SessionId, P_StatefulId
//Step 3
cookieMaster.setCookieValue(searchUrl, cookieArrPair[0], cookieArrPair[1]);
cookieMaster.setCookieValue(searchUrl, cookieArrPair[4], cookieArrPair[5]);
cookieMaster.setCookieValue(searchUrl, cookieArrPair[8], cookieArrPair[9]);
}

No comments:

Post a Comment