I have just started trying to develop android apps. I heard that android studio is an android application development tool supported by Google, so I think it must be easier to use than Eclipse. I have always been doing .net development. I recently used Eclipse and Android Studio and found that Visual studio.net is officially very easy to use. I have to say that Microsoft's development tools are better than anyone else. The following is a lot of detours when I first started using the Android Studio application third-class library, so I wrote it down for beginners like me and shared it.
Import *.jar package
Create a new Android project, add a third-party packaged jar file into your project, and add a package of odata4j below
Add a libs file to the project
Add the jar file you downloaded to the libs folder directly through COPY/PAST
Then click the menu add as library under the libs folder and the added *.jar file
Then select the project, click Open Module Settings, and select Add File in Dependencies
This completes the jar file addition
Open the App directory and there is a build.gradle file that should be the project structure file. The above actions are just to add under the file
dependencies {
compile files('libs/android-support-v13.jar')
compile files('libs/odata4j-0.7.0-clientbundle.jar')
}
Import third-party java class library including source code package
The following shows how to import a third-party source code class library in this project. The example here is to import Httpzoid, a json http client class library
First download the zip package from github, unzip it and copy the Httpzoid directory to the directory of your project
After adding, this directory will automatically appear under the android studio project
接下来需要手工修改项目跟目录下settings.gadle 添加
include ':App',':Httpzoid'
这里必须手工修改没有其他方法
然后在打开App/build.gradle这个文件,添加
dependencies{
compile project(':Httpzoid')
}
这是你在打开Open Module Settings就可以看到,已经导入httpzoid的类库
但是编译肯定还是会错误的
还必须在项目Httpzoid目录下添加一个build.gradle的这个文件,内容如下
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('libs/gson-2.2.4.jar')
}
这是后编译还会有可能报错
这时候可能需要修改一下Httpzoid目录下的AndroidManifest.xml文件有可能存在和你项目中文件有冲突或版本跨度太大导致语法的错误修改一下
做完以上几步基本上就可以便宜成功了