如何将Eclipse中的项目迁移到



Download 104.84 Kb.
Date30.06.2017
Size104.84 Kb.
#22109
Android Studio operation menu

https://developer.android.com/tools/studio/index.html

http://www.vogella.com/tutorials/Android/article.html

Building and Running from Android Studio

https://developer.android.com/tools/building/building-studio.html

如何将Eclipse中的项目迁移到Android Studio


2015/10/1 測試將MySQLAPP匯入成功

1. 開啟Android Studio

2. 點取Import Project from Eclipse

3. 點選待匯入之 Project

4. 出現對話視窗時,將下列預設之勾選取消

Replace jars with dependencies, when possible

Replace library sources with dependencies, when possible

Other options:

Create Gradle-style (camelCase) module names.

即可順利將舊版專案匯入Android Studio


Import 現有專案發生錯誤解決方法




按此處按鈕依序執行對應程序

http://android-studio.org/index.php/docs/guide/129-eclipse-to-androidstdio

1. Eclipse >File>Export>Android>Generate Gradle Build Files

2.



3. Next>Next>選擇舊專案>Next>Finish

4. 再源專案目錄產生build.gradle文件檔

Eclipse中导出
        1.将你的ADT插件版本升级到22.0以上。
        2.Eclipse中,选择File-->Export
        3.在弹出的导出窗口中,打开Android的文件夹,选择“Generate Gradle Build Files”
        4.选中你想要导入到Android Studio中的项目,Finish
PS:导出的项目将会和原来的项目在同一目录,覆盖原来的同时,会新增一个叫build.gradle的文件,导入Android Studio时将首先读取这个文件。
导入到Android Studio
        1.Android Studio 中,首先关掉你当前的打开的项目。
        2.在欢迎界面,点击Import Project(注:也是可以直接在菜单选择Import project的)
        3.选中你在Eclipse中导出的项目,展开目录,点击build.gradle文件,然后OK
        4.在之后的弹出对话框中,会要求你选择Gradle的配置,选中Use gradle wrapper.(注:也可以自定义你本机装的Gradle)
   PS:如果没有Grade build文件,也是可以将普通的安卓项目导入到Android Studio中,它会用现有的Ant build.但为了更好地使用之后的功能和充分使用构建变量,还是强烈地建议先从ADT插件中生成Gradle文件再导入Android Studio

Android Studio 使用指南(汉化)


http://android-studio.org/index.php/docs/guide


如何引入第三方jar包(以google play service为例)


2015/10/12

Test QRCode OK

C:\Android\Example\QRcode\android-integration-3.2.0.jar, C:\Android\Example\QRcode\ core-3.2.0.jar

=> C:\Android\NewApp\MySQLApp\libs

1. 在專案目錄下新增一目錄, 命名為libs

2. 將外來jar檔拷入libs

3. 在Studio libs目錄下對應檔案案右鍵/Add as library /

4. 在跳出視窗下 選擇專案對應目錄 / OK

5. Gradle 會立即同步

6. 稍待片刻 繼續處理其他檔案


http://android-studio.org/index.php/docs/guide/132-androidstudio-inport-jar


How to include JAR file into Android project in Android Studio

http://stackoverflow.com/questions/25660166/how-to-add-a-jar-in-external-libraries-in-android-studio

ANS

Create "libs" folder in app directory copy your jar file in libs folder right click on your jar file in Android Studio and Add As library... Then open build.gradle and add this:

dependencies {

compile files('libs/your jar file.jar')

}


How do I add a library project to the Android Studio?


http://stackoverflow.com/questions/16588064/how-do-i-add-a-library-project-to-the-android-studio

Update for Android Studio 1.0

Since Android Studio 1.0 was released (and a lot of versions between v1.0 and one of the firsts from the time of my previous answer) some things has changed.

My description is focused on adding external library project by hand via gradle files (for better understanding the process). If you want to add library via Android Studio creator just check theanswer below with visual guide (there are some differents between Android Studio 1.0 and those from screenshots, but the process is very similar).

Before you start adding library to your project by hand consider adding external dependency. It won’t mess in your project structure. Almost every well known Android library is available in maven repository and its installation takes only one line of code in app/build.gradle file:

dependencies {

compile 'com.jakewharton:butterknife:6.0.0'

}

Adding the library

Here is the full process of adding external Android library to our project:



  1. Create new project via Android Studio creator. I named it HelloWorld

  2. Here is the original project structure created by Android Studio:

HelloWorld/

app/


- build.gradle // local gradle config (for app only)

...


- build.gradle // global gradle config (for whole project)

- settings.gradle

- gradle.properties

...


  1. In root directory (HelloWorld/) create new folder: /libs in which we’ll place our external libraries (this step is not required - only for keeping cleaner project structure).

  2. Paste your library in newly created /libs folder. In this example I used PagerSlidingTabStrip library (just download ZIP from Github, rename library directory to „PagerSlidingTabStrip" and copy it). Here is the new structure of our project:

HelloWorld/

app/


- build.gradle // local gradle config (for app only)

...


libs/

PagerSlidingTabStrip/

- build.gradle // local gradle config (for library only)

- build.gradle // global gradle config (for whole project)

- settings.gradle

- gradle.properties

...


  1. Edit settings.gradle by adding your library to include. If you use custom path like I did, you have also define project directory for our library. Whole settings.gradle should look like below:

  2. include ':app', ':PagerSlidingTabStrip'

project(':PagerSlidingTabStrip').projectDir = new File('libs/PagerSlidingTabStrip')

5.1 If you face "Default Configuration" error, then try this instead of step 5,

include ':app'

include ':libs:PagerSlidingTabStrip'



  1. In app/build.gradle add our library project as an dependency:

  2. dependencies {

  3. compile fileTree(dir: 'libs', include: ['*.jar'])

  4. compile 'com.android.support:appcompat-v7:21.0.3'

  5. compile project(":PagerSlidingTabStrip")

}

6.1. If you followed step 5.1, then follow this instead of 6,

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.android.support:appcompat-v7:21.0.3'
compile project(":libs:PagerSlidingTabStrip")

}


  1. If your library project doesn’t have build.gradle file you have to create it manually. Here is example of that file:

  2. apply plugin: 'com.android.library'



  3. dependencies {

  4. compile 'com.android.support:support-v4:21.0.3'

  5. }



  6. android {

  7. compileSdkVersion 21

  8. buildToolsVersion "21.1.2"



  9. defaultConfig {

  10. minSdkVersion 14

  11. targetSdkVersion 21

  12. }



  13. sourceSets {

  14. main {

  15. manifest.srcFile 'AndroidManifest.xml'

  16. java.srcDirs = ['src']

  17. res.srcDirs = ['res']

  18. }

  19. }

}

Additionaly you can create global config for your project which will contain SDK versions and build tools version for every module to keep consistency. Just edit gradle.properties file and add lines:

ANDROID_BUILD_MIN_SDK_VERSION=14

ANDROID_BUILD_TARGET_SDK_VERSION=21

ANDROID_BUILD_TOOLS_VERSION=21.1.3

ANDROID_BUILD_SDK_VERSION=21

Now you can use it in your build.gradle files (in app and libraries modules) like below:

//...


android {

compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)

buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {

minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)

targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)

}

}



//...

That’s all. Just click ‚Sync project with gradle’ icon . Your library should be available in your project.

Simple way to add JAR file as library to your Android Studio project:

a) Copy your *.jar files

b) Paste into libs directory under your projects

c) Add to build.gradle



dependencies {

...

compile files('libs/ScanAPIAndroid.jar', 'libs/ScanAPIFactoryAndroid.jar', .., ..)

}

b) IF Your project from example com.example.MYProject and libraries com.example.ScanAPI has the same namespace com.example: Android studio will check your build and create all necessary changes in your project. After than you can review these settings in File->Project Structure

c) IF Your project and libraries has different namespace you have to RigthClick on library and select OPTION "Add as Library" and select type what you need.

Remember "Project structure" option is not doing any auto changes in "build.gradle" in current version Android studio (0.2.3) maybe this feature will be available in next versions.




http://www.vogella.com/tutorials/Android/article.html

6.2. Debug certificate and expire date


Android applications must be signed before they can get installed on an Android device. During development Eclipse signs your application automatically with a self-signed certificate called the debug key.

This debug certificate has an expiration date of 365 days from its creation date. When the certificate expires, you will get a build error that the certificate has been expired.

To fix this problem, delete the debug.keystore file. The default storage location is in ~/.android/ on OS X and Linux, inC:\Documents andSettings\[username]\.android\ on Windows XP, and in C:\Users\[username]]\.android\ on Windows Vista and Windows 7.

The next time you build, the build tools will regenerate a new keystore and debug key.


6.3. Android device emulator shortcuts


The following table lists useful shortcuts for working with an AVD.

Table 1. Android device emulator shortcuts



Shortcut

Description

Alt+Enter

Maximizes the emulator.

Ctrl+F11

Changes the orientation of the emulator from landscape to portrait and vice versa.

F8

Turns the network on and off.


6.4. Google vs. Android AVD


During the creation of an AVD you decide if you want to create an Android device or a Google device.

An AVD created for Android contains the programs from the Android Open Source Project. An AVD created for the Google API's contains additional Google specific code.

AVDs created for the Google API allow you to test applications which use Google Play services, e.g., the new Google maps API or the new location services.

6.5. Speed optimization with GPU rendering


During the creation of an emulator you can choose if you either want Snapshot or Use Host GPU enabled.

Note


 

The dialog implies that you can select both options, but if you do, you get an error message that these options can not be selected together.

If you select the Snapshot option, the second time you start the device it is started very fast, because the AVD stores its state if you close it. If you select Use Host GPU the AVD uses the graphics card of your host computer directly which makes the rendering on the emulated device much faster.



22. Assets

22.1. Whats are assets?


While the res directory contains structured values which are known to the Android platform, the assets directory can be used to store any kind of data.

You can access files stored in this folder based on their path. The assets directory also allows you to have sub-folders.


Note


 You could also store unstructured data in the /res/raw folder, but it is considered good practice to use theassets directory for such data.

22.2. Accessing assets


You access this data via the AssetsManager which you can access via the getAssets() method from an instance of theContext class.

The AssetsManager class allows you to read a file in the assets folder as InputStream with the open() method. The following code shows an example for this.



// get the AssetManager

AssetManager manager = getAssets();


// read the "logo.png" bitmap from the assets folder

InputStream open = null;



try {

open = manager.open("logo.png");

Bitmap bitmap = BitmapFactory.decodeStream(open);

// assign the bitmap to an ImageView in this layout

ImageView view = (ImageView) findViewById(R.id.imageView1);

view.setImageBitmap(bitmap);

} catch (IOException e) {

e.printStackTrace();

} finally {



if (open != null) {

try {

open.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}


25. Deployment

25.1. Overview


In general there are restrictions how to deploy an Android application to your device. You can deploy the application via USB in test mode onto your device , email yourself the application or use one of the many Android markets to install the application. The following description highlights the most common ones.

25.2. Defining software and hardware requirements for the application


The application can define via a declaration in the manifest file define which hardware of software features is requires. Via the android:required property the application can define if such a feature is required for the application to work correctly (true) or if application prefers to use the feature if present on the device, but that it is designed to function without the specified feature, if necessary.

Examples for such definitions are the presence of a certain hardware sensor or the availability of a camera.

For an overview of the available restrictions see uses-features official documentation.

25.3. Signing your application for the release


Android applications must be signed before they can get installed on an Android device. During development Eclipse signs your application automatically with a debug key.

To install the Android application via another channel you need to sign the Android apk with a self-created signature key.

Please note that you need to use the same signature key in Google Play (Google Market) to update your application. If you lose the key, you will NOT be able to update your application ever again.

Make sure to backup your key.


25.4. Export your application via Android Studio


Use the Build → Generate Signed APK... menu entry to start the export from Android Studio.

25.5. Export your application via the Eclipse IDE

If you want to export your production application via the Eclipse IDE, you can right-click on it and select Android Tools → Export Signed Application Package.

This wizard allows to use an existing key or to create a new one.


25.6. Via external sources


Android also allows to install applications directly. Just click on a link which points to an .apk file, e.g., in an email attachment or on a webpage. Android will prompt you if you want to install this application.

This requires a setting on the Android device which allows the installation of non-market application. Typically this setting can be found under the "Security" settings.


25.7. Google Play (Market)


Google Play requires a one time fee, currently 25 Dollar. After that the developer can directly upload his application and the required icons, under Google Play Publishing.

Google performs some automatic scanning of applications, but no approval process is in place. All application, which do not contain malware, will be published. Usually a few minutes after upload, the application is available.

Download 104.84 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page