Saturday, March 16, 2019

Android开发笔记-ch3.5 Android SDK & Library


3.5 Android SDK & Library

3.5.1 SDK, version, and Sample

SDK 23.0.2, Error: aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
Install zlib1g might not work. Need to specify as: zlib1g:i386. Or refer to this: old SDK is 32bit only, to run on x64, need to do:
sudo apt-get install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386 => may need reboot?
for running the emulator you need that additional package: sudo apt-get install libsdl1.2debian:i386
ADT doesn't work with SDK25+. Refer to above 1.4. For samples, refer to this. The left list for navigating between all sample projects.
For compileSdkVersion and targetSdkVersion, refer to this SO:The targetSdkVersion has nothing to do with how your app is compiled or what APIs you can utilize. The targetSdkVersion is supposed to indicate that you have tested your app on (presumably up to and including) the version you specify. This is more like a certification or sign off you are giving the Android OS as a hint to how it should handle your app in terms of OS features. So better set targetSdkVersion to newest version. Chose a compileSdkVersion >= minSdkVersion, and don't use API not available in minSdkVersion. May got runtime warning when running the app on a platform which has API lower than the compileSdkVersion: W/dalvikvm: VFY: unable to resolve virtual method 21001: Landroid/view/ViewPropertyAnimator; which can safely be ignored.

3.5.2 AVD

In old day, emulater for ARM has limitation: only can support up to 1280x800 resolution. For 1920x1080, use x86 emulater and enable Host GPU. For Intel x86 Emulator Accelerator HAXM, install it with SDK manger is not enough, also need to run IntelHAXM.dmg (IntelHAXM.exe on Windows) installer, located in the Android SDK under /extras/intel/Hardware_Accelerated_Execution_Manager/.
If got INSTALL_FAILED_NO_MATCHING_ABIS when loading an APP on AVD, refer to this so, it means you are trying to install an app that has native libraries and it doesn't have a native library for your cpu architecture. For example if you compiled an app for armv7 and are trying to install it on an emulator that uses the Intel architecture instead it will not work. However, as the host PC is x86, running x86 emulator is 10x faster than the ARM AVD.

3.5.3 Support Library

Android Support Library package is part of SDK. Refer to this setup guide. As mentioned there, for Android Studio, select and install the Android Support Repository item instead. How you setup the Android Support Libraries in your development project depends on what features you want to use and what range of Android platform versions you want to support with your application. Before adding a
Support Library to your application, decide what features you want to include and the lowest Android versions you want to support. For more information on the features provided by the different libraries, see Support Library Features. The guide is updated for gradle. For old way, refer to my android note: libraries can be added with or w/o resources. For w/o resources, just copy the jar file to libs folder (create it if not exist), and it should show up in project’s Properties->Java Build Path->Libraries tab->Android Private Libraries(if not, try to add it to build path). For with resources(such as v7 appcompat for action bar), will need to create a library project as described here, build it, and add reference to other project to use the lib exported functions.
For Android Design Support Library mentioned in 3.4.4, seems need to build the lib with resource. To do that with Eclipse/ADT, I created a new Android project with exist code=>select the root from SDK/extras/android/support/design=>check “Copy projects into workspace” =>in Project properties, change the target to the latest such as Android 6.0, check 'Is Library', also, according to this SO, it depends appcompat_v7, so add that project as dependency. With this setting, the support design lib can be built successfully.
However, when I try to use this lib in a project for TabLayout, there are many runtime issue, such as NoClassDefFoundError with android.support.v7.widget.TintManager, and I cannot find the package from the SDK anywhere. Not much clue from Internet search either. So it is time to switch to Android STUDIO.
For using Google Player Service, follow this. When build it, might get “error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Material.Light.DialogWhenLarge.NoActionBar'”. I got it resolved by change target from Android 4.1.2 to Google APIs. Also need to change the App project target setting to Google APIs as well. Otherwise might get stranger problem, such as lot of error of R.java, which cannot be generated without error, the error might show in console like: google-play-services_lib/res/values-v21/appinvite_styles.xml:5: error: Error retrieving parent for item: No resource found that matches the given name'@android:style/Theme.Material.Light.DialogWhenLarge.NoActionBar'. Very frustrate as no clue of what's wrong. After raising the target level, may see increating of warning due to deprecated APIs.
Lot of problem after pull in Google Player Service with Eclipse, may due to the size limitation. Refer to this SO. As said. Uncheck private lib may help build, but will get runtime problem. So the best solution for Eclipse might be strip the google lib: unzip the file google-play-services.jar , go in the the unzipped folder and remove all folders that you don't need (i.e. if you need Analytics, you can remove ads, games, maps, wallet, drive, etc.)

3.5.4 External lib: jar and aar

For jar vs. aar, refer to this SO. aar is jar+resource, which usually is an output from Android Studio. Just like some feature in Andorid Support Library, some lib has to be linked with its resource together. Refer to this blog for convert it to ADT jar(kind of create a android lib project to be referenced). Or refer to this SO for using Android Maven plugin.

3.5.5 Developing on multiple PC

Might see “Re-installation failed due to different application signatures”, share the %USER_HOME%/.android/debug.keystore

0 Comments:

Post a Comment