Wednesday, March 6, 2019

Android开发笔记-ch1


1. Setup Environment

In order to setup for working at both office and home, with different PC, I will try to use Linux (Ubuntu LTE14.05/64bit) environment. So I may use an USB driver as storage of my project. I will use Eclipse for common code exercise and will use Android Studio for project for release.

1.1 Setup Portable Linux

I followed this link to install Ubuntu 14.04 on a USB harddrive to allow me using it with different PC: UEFI-and-BIOS => A new and so far successful attempt to create a stable portable system, that works in UEFI and BIOS mode, which create a Portable drive contains a live system and an installed system, and both work in UEFI and BIOS mode. Detail steps as:
1) Use mkusb to install following image to the USB drive: http://phillw.net/isos/linux-tools/uefi-n-bios/dd_Ubuntu_14.04.2-UEFI-n-BIOS-10GB.img.xz, which is output of the instruction steps A~D.
2) Follow instruction part 2: add 'noatime' for ext4 in /etc/fstab; follow GrowIt.pdf to adjust partition size, and user/pw: guru/changeme
Somehow swapoff doesn't work for me. I tried mkswap and that destroyed the partition and I have to do mkusb again. I'm able to run gparted w/o swapoff. As the instruction said, following has been tweaked:
.../usb-live/syslinux/txt.cfg  =>for legacy BIOS mode, not UEFI, not used after certain update/upgrade
.../usb-live/boot/grub/grub.cfg =>for UEFI
.../usb-installed/boot/grub/grub.cfg =>for legacy BIOS mode, used directly after certain update which may wipe off boot from live
To make it boot with the installed Ubuntu, modify the first txt.cfg file, change the default from live to ubu-installed. I also modified syslinux.cfg to comment out “default vesamenu.c32” and “ui gfxboot bootlogo” as those might override the default setting in txt.cfg. Interesting, according to syslinux wiki, it is using capital case keyword, but the cfg files above are all using little case, just like LILO, the legacy Linux Loader.
Very likely will need sshd, so install openssh server: sudo apt-get install openssh-server
Install 7zip: sudo apt-get install p7zip-full for supporting ecnrypted 7z file.
For running Emulator, refer to SO, emulator and KVM. Install KVM sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
For 14.04 LTS, no need to do adduser as it will be added by default. Just re-login. But this doesn't fix tmissing libstdc++.so.6 problem. sudo apt-get install lib32stdc++6 does help.
For chinese input/pinin problem, refer to this: try ibus-daemon -drx or just reinstall ibus-daemon.

1.2 Setup JDK

I installed Oracle JDK8(note Eclipse needs Java7+ and it mentions there is issue with openjdk8) by download the tar.gz file, extract and move to a common folder such as /usr/jdk. After that, either setup environment variable “JAVA_HOME” and “PAHT”, or do following:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/jdk/jdk1.8.0_65/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/jdk/jdk1.8.0_65/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/jdk/jdk1.8.0_65/bin/javaws" 1
Refer to this link for more info. Though OpenJDK8 is available with sudo apt-get install openjdk8-jdk, there is issue with Android SDK.
Refer this to enable Java plugin for Firefox: cd firefox-addons/plugins && sudo ln -s /usr/jdk/jdk1.8.0_121/jre/lib/amd64/libnpjp2.so

1.3 Install ADT and Android SDK`

Add this repository to Eclipse: https://dl-ssl.google.com/android/eclipse/. It will also install Android SDK. As my old android doc mentioned, Difference between Android and Google API: Google API includes Google Maps and other Google-specific libraries. The Android one only includes core Android libraries. I installed Google API as I need Google Maps functionality. Also installed Google Play services to take advantage of the latest, Google-powered features such as Maps, Google+, and more, with automatic platform updates distributed as an APK through the Google Play store. This makes it faster for users to receive updates and easier for me to integrate the newest that Google has to offer.
On my new portable hd, I got a wierd error when running adb: “No such file or directory”. Thanks to this post: You can see all the libs needed for an executable by running: objdump -x ./adb | grep NEEDED
Running adb on x64 needs ia32-libs package, but this package was removed in 14.04, gcc-multilib is the closest drop-in as replacement.
Google moves their support to Android Studio away from ADT. So if see “This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in” with Graphical Layout, chance is no way to update ADT, but lower the API level will help. Refer to this SO.

1.4 Install Andriod Studio

First time run studio.sh, it will run setup wizard. I chose custom as I want to share the same Android SDK with Eclipse/ADT. So during the setup, change the SDK location to the exist one and it prompt only install missing or out-dated component.
After install, also need to setup JDK path(Menu=>File=>Project Structure=>SDK location), otherwise it won't build and run. And with an imported Android sample project, it also needs selection of SDK(API level), then it will do gradle sync and build automatically.
Note: after upgrade to Android Studio 2.3, it removed SDK manager executable, lead to Eclipse failed to launch the SDK. Refer to this SO. It won't be easy to get it back on linux. The command to start the manager used to be: tools/android sdk, which also need several jar from tools/lib folder. The way I got it worked by merging the tools folder from old SDK: after the SDK is updated, copy the tools folder from old SDK but DO NOT overwrite any exist file except the script file 'android'.

1.5 Setup git

Git should be set per project, for tracking all changes. Run sudo apt-get install git to have the package
1) git init
2) create .gitignore => there are many refs, and many recommend: http://www.gitignore.io
3) git add --all, then git commit
My github: https://github.com/quyq, associated with my gmail account, pw is old address.
To create patches, run git format-patch hash_of_start_point
Refer this SO for setting git on google driver and this for setting up Google drive Grive2 on Ubuntu:
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install grive
Then create a grive folder, and run grive -a for permission, and grive -S subfolder for syncing a subfolder. To push local git such as my iFunTV to Google drive: cd ~/grive && mkdir ifun && cd ifun && git init --bare; then CD to local git folder and run: git remote add origin file:///home/$USER/grive/ifun && git push origin master; Then run grive under ~/grive, which will sync local changes with Google drive.
For git share between windows and linux, may get filemode and CRLF problem, refer to this so and this so, and git-scm book:
on linux: The proper way to solve this kind of situation is to handle folder and file permission separately, with something like:
find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \;  # Make files read/write
git config --global core.fileMode false
git config --global core.autocrlf input

0 Comments:

Post a Comment