Setting Up Sudoku Example On Android Studio

Transcription

Installing Android StudioSetting up Sudoku example on Android StudioInstalling Android StudioAndroid Studio prov ides everything you need to start dev eloping apps for Android,including the Android Studio I DE and the Android SDK tools.I f you didn't dow nload Android Studio, go download Android Studio now.Before you set up Android Studio, be sure you hav e installed JDK 6 or higher (the JREalone is not sufficient)—JDK 7 is required w hen developing for Android 5.0 and higher.To check if you hav e JDK installed (and w hich v ersion), open a terminal and type javac-version. I f the JDK is not av ailable or the v ersion is low er than 6, go dow nload JDK.To set up Android Studio on Windows:1. Launch the .exe file you just dow nloaded.2. Follow the setup w izard to install Android Studio and any necessary SDK tools.On some Window s systems, the launcher script does not find w here Java isinstalled. I f you encounter this problem, you need to set an env ironment v ariableindicating the correct location.Select Start menu Computer System Properties Advanced SystemProperties. Then open Advanced tab Environment Variables and add a newsystem v ariable JAVA HOME that points to your JDK folder, for example C:\ProgramFiles\Java\jdk1.7.0 21.The indiv idual tools and other SDK packages are sav ed outside the Android Studioapplication directory. I f you need to access the tools directly, use a terminal tonav igate to the location w here they are installed. For example:\Users\ user \sdk\To set up Android Studio on Mac OSX:1. Launch the .dmg file you just dow nloaded.2. Drag and drop Android Studio into the Applications folder.3. Open Android Studio and follow the setup w izard to install any necessary SDKtools.Depending on your security settings, w hen you attempt to open Android Studio,you might see a w arning that says the package is damaged and should bemov ed to the trash. I f this happens, go to System Preferences Security &Mobile Application Development NORTHEASTERN UNIVERSITY1

Adding SDK PackagesPrivacy and under Allow applications downloaded from, select anywhere. Thenopen Android Studio again.I f you need use the Android SDK tools from a command line, you can access them at:/Users/ user /Library/Android/sdk/To set up Android Studio on Linux:1. Unpack the dow nloaded ZIP file into an appropriate location for yourapplications.2. To launch Android Studio, nav igate to the android-studio/bin/ directory in aterminal and execute studio.sh.You may w ant to add android-studio/bin/ to your PATH env ironmental variableso that you can start Android Studio from any directory.3. Follow the setup w izard to install any necessary SDK tools.Android Studio is now ready and loaded w ith the Android dev eloper tools, but thereare still a couple packages you should add to make your Android SDK complete.Adding SDK PackagesBy default, the Android SDK does not include ev erything you need to start dev eloping.The SDK separates tools, platforms, and other components into packages you candow nload as needed using the Android SDK Manager. So before you can start, thereare a few packages you should add to your Android SDK.To start adding packages, launch the Android SDK Manager in one of the follow ingw ays: I n Android Studio, click SDK Managerin the toolbar.I f you're not using Android Studio:o Window s: Double-click the SDK Manager.exe file at the root of the AndroidSDK directory.o Mac/Linux: Open a terminal and nav igate to the tools/ directory in theAndroid SDK, then execute android sdk.When you open the SDK Manager for the first time, sev eral packages are selected bydefault. Leav e these selected, but be sure you hav e everything you need to get startedby follow ing these steps:Mobile Application Development NORTHEASTERN UNIVERSITY2

Adding SDK Packages1. Get the latest SDK toolsAs a minimum w hen setting up the Android SDK, you should dow nload the latesttools and Android platform:1. Open the Tools directory and select: Android SDK Tools Android SDK Platform-tools Android SDK Build-tools (highest v ersion)2. Open the first Android X.X folder (the latest v ersion) and select: SDK Platform A system image for the emulator, such asARM EABI v7a System Image2. Install the packagesOnce you'v e selected all the desired packages, continue to install:1. Click Install X packages.2. I n the next w indow, double-click each package name on the left toaccept the license agreement for each.3. Click Install.The dow nload progress is shown at the bottom of the SDK Manager w indow. Donot exit the SDK Manager or it w ill cancel the download.Note: You should ideally download the latest version against which you compile yourapplication and the version which you intend to target the application. In this case - Android5.0.1 (API 21) and Android 2.3.3 (API 10) respectively.Mobile Application Development NORTHEASTERN UNIVERSITY3

Importing Sudoku codeImporting Sudoku code1. I n Android Studio, click on Import Project from the File menu.2. Brow se to the directory where you extracted the code and select Sudokuv4Mobile Application Development NORTHEASTERN UNIVERSITY4

Importing Sudoku code3. I t w ill recognize the Project from ADT. Choose a destination directory for the import.4. Click on the Finish button.Mobile Application Development NORTHEASTERN UNIVERSITY5

Importing Sudoku code5. After importing the project, the configurations w ill be modified from ADT Eclipseproject to Android Gradle as Android Studio uses Gradle build.6. I t w ill display a summary of the changes done as Android Gradle projects use adifferent structure than ADT Eclipse projects. Android Studio modifies the structure of theproject accordingly, so you do not need to w orry.Mobile Application Development NORTHEASTERN UNIVERSITY6

Importing Sudoku code7. Your project structure w ill look like this.Mobile Application Development NORTHEASTERN UNIVERSITY7

Importing Sudoku code8. Open the AndroidManifest.xml and scroll to the bottom. The uses-sdk tag w ill hav ean android:minSdkVersion ”3” declaration which is an integer designating theminimum API Level required for the application to run. Despite its name, this element isused to specify the API Level, not the v ersion number of the SDK (softw are developmentkit) or Android platform. The API Level is alw ays a single integer.9. To change the minimum v ersion or the target v ersion, right-click on the app module,and click on Open Module Settings.Mobile Application Development NORTHEASTERN UNIVERSITY8

Importing Sudoku code10. I n the Properties tab, the compile v ersion is set to the latest v ersion of Androidav ailable in your SDK.Tip: Choose the highest platform version available so that your application will beoptimized for greater user experience on the latest devices.11. I n the Flav ors tab, you w ill see the minimum v ersion as w ell as the target v ersion. Forthe Sudoku example, the minimum v ersion is set to “3” by default.Mobile Application Development NORTHEASTERN UNIVERSITY9

Importing Sudoku code12. For the target v ersion, set the Android v ersion to 2.3.3 (Gingerbread) w hich is APILev el 10.android:minSdkVersionAn integer designating the minimum API Level required for the application to run. TheAndroid system w ill prevent the user from installing the application if the system's APILev el is lower than the v alue specified in this attribute.android:targetSdkVersionAn integer designating the API Level that the application targets. I f not set, the defaultv alue equals that giv en to minSdkVersion.This attribute informs the system that you hav e tested against the target v ersion and thesystem should not enable any compatibility behav iors to maintain your app's forw ardcompatibility w ith the target v ersion. The application is still able to run on older v ersions(dow n to minSdkVersion).Mobile Application Development NORTHEASTERN UNIVERSITY10

Importing Sudoku code13. Run the application by clicking on the ‘Run app’ (Alt Shift X) from the Run menu.14. Select the ‘Launch emulator’ option and choose a Android v irtual device.Mobile Application Development NORTHEASTERN UNIVERSITY11

Importing Sudoku code15. The AVD launches in a separate w indow.16. The Sudoku application w ill run like below in the AVD. You’re all set!References:https://dev eloper.android.com/sdk/installing/index.html?pkg studiohttps://dev htmlhttps://dev element.htmlMobile Application Development NORTHEASTERN UNIVERSITY12

Installing Android Studio 1 Mobile Application Development NORTHEASTERN UNIVERSITY Setting up Sudoku example on Android Studio Installing Android Studio Android Studio provides everything you need to start developing apps for Android, including the Android Studio