[Method] android application Android Studio to import third-party libraries

Recently doing related applications a two-dimensional code, incidentally relevant knowledge gathering information. Today reprint of this practical for me to solve the jar package into question. Because android studio with fewer, reproduced records to facilitate future under forget conduct a search. Respecting the original case, a little to do a little fine-tuning.

Reprinted from: https://www.cnblogs.com/neozhu/p/3458759.html

Invasion delete, thank you.


I have just started trying to do to develop android app, I heard Google android studio is supported by android application development tools, so think it should certainly easy to use than Eclipse, anyway, no previous experience in java development, simply started to learn from android studio, before .net development has been done recently using Eclipse, Android Studio Visual studio.net after the discovery officially handy, have to say that Microsoft's development tools to do better than anyone else. Here is my third time using Android Studio application libraries beginning of quite a few detours, so write it down for a beginner like me, share.

Import * .jar package

Well, the new Android project, add a third party has packaged jar files into your project, add a package had been following a odata4j

Libs add a file in the project

Directly by adding COPY / PAST jar file you downloaded to the libs folder

Then in the libs folder and add the * .jar file click menu add as library

Then select an item, click Open Module Settings, select Add files in Dependencies

This completes the jar files

There build.gradle project file should open App directory structure of the file, the above operation just to add in the file

dependencies {

compile files('libs/android-support-v13.jar')

compile files('libs/odata4j-0.7.0-clientbundle.jar')

}

As long as you see in build.gradle library file, add it shows a success.

Import java class library containing third-party source code package

下面演示如何在本项目中导入第三方的源代码类库,这里例子是导入Httpzoid一个json http client类库

先从github上下载zip包解压后把Httpzoid目录copy到你项目的目录下

添加后android studio的项目下会自动出现这个目录

接下来需要手工修改项目跟目录下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文件有可能存在和你项目中文件有冲突或版本跨度太大导致语法的错误修改一下

做完以上几步基本上就可以便宜成功了

 

最后吐槽一下

Java的IDE开发工具真的很搓和Visual Studio.net没法比;最糟糕的就是Debug,显示的都是内存地址而不是值,Debug异常也不会自动停止在出错的代码行。

Guess you like

Origin blog.csdn.net/twk121109281/article/details/93601300