1 Background Introduction
With the improvement and popularity of Android studio, more and more Android app developers have been transferred from the Eclipse+adt environment to Android Studio (as represented by unified as in the following article). However, as often requires a newer SDK, from the current test results, many of the Mac OSX 10.10 system based on the old version of the SDK development is not perfect to run in the new version of the SDK, that the two are not perfectly compatible, for example, in the eclipse+ The emulator image or snapshot created in the ADT environment cannot be used in as (specifically, the emulator or snapshot fails to start or crash immediately after startup). Therefore, the best solution is to use two sets of SDKs in the system at the same time, the old version is used for Eclipse, the new version is used for AS.
The main problem detected at the moment is DDMS, and it seems that the DDMS in the new SDK will not be compatible with the older version of Eclipse. For specific reasons, you'll have time to dig in later.
2 How to create two sets of SDKs
Creating two sets of SDKs is simple, but how to make the two sets of SDKs run independently and without interference is relatively cumbersome. For the convenience of description, the old version of the SDK directory is called OLD_SDK, the new version of the SDK directory is called NEW_SDK.
First of all, because the author is currently in Eclipse development, so the default SDK is OLD_SDK, only when using as to use the NEW_SDK. Therefore, the author has made the following configuration in the ~/.bash_profile file:
#default sdkexport android_home=/users/your_user_name/android/env/old-android-sdks
This way we start the program by default is to use the above OLD_SDK directory. So how do you use NEW_SDK when starting as? This is also done in ~/.bash_profile, where we add an alias command:
# set new SDK envrionment for Android Studio
Alias myas='export Android_home=/users/your_user_name/android/env/new-android-sdks && open-a/ applications/android\ studio.app/'
With the above settings, we only need to enter Myas in the terminal when we need to use as. But this is not perfect, because if we open a new terminal and then use the ADB command, it defaults to using the old version of ADB, which is more or less a compatibility issue. Why is that? The answer is set in the PATH environment variable in Bash_profile:
Export path=/user/local/bin: $PATH: $ANDROID _home/tools: $ANDROID _home/platform-tools
Because the value of path is set before we change Android_home, the android_home at this time is old_sdk. So the best way is to provide an alias command to switch android_home and path at once:
for Android studioalias change_android_sdk='export Android_home=/users/your_user_name/android/ Env/new-android-sdks && Export path= $ANDROID _home/tools: $ANDROID _home/platform-tools: $PATH' alias Myas='change_android_sdk && open-a/applications/android\ studio.app/'
With the above settings, it is ensured that NEW_SDK is used in the as, and when we are programming in the as environment, if we want to use commands such as ADB, you can switch to New_ by using the CHANGE_ANDROID_SDK command in the new terminal. SDK.
3 Some strange bug collections encountered
Problem one: Simulator snapshot crash problem
Note: For convenience, the author uses the emulator command to initiate a snapshot of the emulator, rather than through emulator Devices manager.
the snapshot was not compatible with NEW_SDK because it was originally a snapshot of the emulator created using OLD_SDK. The specific crash scenario is:
Start the snapshot in the OLD_SDK environment first, everything is OK.
Then use Myas to open Android Studio, everything works.
Then run an app into the snapshot in Myas, everything works.
When you close the snapshot and then restart the snapshot, a bug occurs, the snapshot does not start, or crash quickly!
Why is that? Because the ADB that is running in the current system after the as is started, the components such as DDMS are from NEW_SDK, and the snapshot initiated by the author must be based on OLD_SDK, so there is a compatibility issue.
The solution is as follows:
First turn off Android Studio and then open Eclipse (open with a new terminal using the Open command, or boot directly from the system's own shortcut), and Eclipse will automatically launch the necessary components in OLD_SDK that meet the Eclipse run ( such as ADB, DDMS, etc.), and these components will replace the current system in the running, as started by the NEW_SDK components, when we start the emulator snapshot there is no problem!
4 Summary
Simulator Snapshot crash problem card The author for a full two days, for the sake of a System Restore O (╯-╰) O. It's lucky to finally be able to solve this problem, because you can finally maintain the original eclipse environment while enjoying the efficient development of Android Studio!
Given the similarity between Mac and Linux, the above scenario should also be applied to the Linux environment, except that the above. bash_profile files will vary according to the specific system, and the common equivalent filenames are as follows:
. bash_login. BASHRC. Profile
How to configure two sets of ANDROID-SDK environments in Mac