2016-10-18 09:51:33 LVXIANGAN 阅读数 10254

Android Studio 项目在gradle文件中,我们通常会发现dependencies闭包中写法如下:



对应的依赖类型可以通过Module Setting 去设置,如图:



各种类型区别如下:

Compile
compile是对所有的build type以及favlors都会参与编译并且打包到最终的apk文件中。

Provided
Provided是对所有的build type以及favlors只在编译时使用,类似eclipse中的external-libs,只参与编译,不打包到最终apk

APK
只会打包到apk文件中,而不参与编译,所以不能在代码中直接调用jar中的类或方法,否则在编译时会报错

Test compile
Test compile 仅仅是针对单元测试代码的编译编译以及最终打包测试apk时有效,而对正常的debug或者release apk包不起作用

Debug compile
Debug compile 仅仅针对debug模式的编译和最终的debug apk打包。

Release compile
Release compile 仅仅针对Release 模式的编译和最终的Release apk打包。



2015-06-25 15:07:06 vispin 阅读数 6100

Warning: Project App: provided dependencies can only be jars. com.android.support:appcompat-v7:22.2.0 is an Android Library
Warning: Project App: provided dependencies can only be jars. com.android.support:support-v4:22.2.0 is an Android Library.

以上是AndroidStudio报的错,


我的build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    provided 'com.android.support:appcompat-v7:22.2.0'
    provided 'com.android.support:support-v4:22.2.0'
}

解决方案:

1.打开项目设置



2.修改gradle版本



3.完成重新编译一下,祝你成功!



2018-12-19 10:12:43 Sindyue 阅读数 1026

Android Studio 从 2.3 升级到3.2以后,对于旧工程的引入,需要如下处理:

1. 工程下的引入studio 版本和 gradle 的版本需要跟进,如studio 3.2.1和gradle 4.6:

dependencies {
	classpath 'com.android.tools.build:gradle:3.2.1'
	// NOTE: Do not place your application dependencies here; they belong
	// in the individual module build.gradle files
}

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

2. project的build.gradle文件中删除

1)classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
	module的build.gradle文件中删除
2)apply plugin: 'com.neenbedankt.android-apt'
	module的build.gradle文件中替换
3)//apt 'com.jakewharton:butterknife-compiler:8.0.1'
	annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'

3. buildVersionCode 可以删除掉

高版本中,buildVersionCode可以省略不些,系统会自动选用合适的版本进行编译。
如果不去掉,要查看兼容的最低版本是多少,相应提高。

4. compile 相关关键词替换

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation' .
Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' .
Configuration 'provided' is obsolete and has been replaced with 'compileOnly'.

‘implementation’ and 'api’的区别,详情可参考链接 https://www.jianshu.com/p/8962d6ba936e
这是因为implementation只能用于当前的module,倘若在库中用这种方式设置依赖,我们在app的module就引用不到。但是api可以。
如果遇到有些api无法识别的,可以替换 “implementation”试试。
另外有两点需要注意:

Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.
It will be removed at the end of 2018.
Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestImplementation'.
It will be removed at the end of 2018.

5. All flavors must now belong to a named flavor dimension.

在主app的build.gradle里面的
defaultConfig {
	targetSdkVersion:***
	minSdkVersion :***
	versionCode:***
	versionName :***
	//版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了
	flavorDimensions "versionCode"
}

6. manifest中不能再指定 minSdk version,可在对应的build.gradle文件中配置。

The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.

7. AndroidStudio3.0 以上版本,之前项目的butter knife报错,用到注解的应该都会报错

Error:Execution failed for task ':app:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - butterknife-7.0.1.jar
  Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
  See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

在app的build中,添加如下语句:

android {
    ...
    defaultConfig {
        ...
        //添加如下配置就OK了
        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
    }
    ...
}

8. 没有google相关文件报的错

Could not find com.android.tools.build:gradle:3.2.1.
Searched in the following locations:
    https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
    https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
Required by:
    project :
Add Google Maven repository and sync project
Open File

在项目的gradle文件中,添加如下maven:

repositories {
	...
	maven {
		url 'https://maven.google.com/'
		name 'Google'
	}
}

9. Error:Unable to resolve dependency for ‘:@debug/compileClasspath’,Could not resolve project

造成这个错误的原因是app下build.gradle里面的buildtypes配置和module下build.gradle中的
buildtypes配置不一样。
解决方案:app下build.gradle里面的buildtypes配置和module下build.gradle中的buildtypes配置要一样。

PS:升级后会遇到各种问题,一定要尽量正确解决问题,否则可能会出现错误方式导致的错误问题,最终导致无解。。。

2017-06-15 09:59:19 qq_15700209 阅读数 1764

1.将公有改为私有,将出现问题的jar包文件修改为私有属性,使其不出现混淆引用问题

dependencies {
    provided files('libs/ormlite-android-4.42.jar')
    provided files('libs/ormlite-core-4.42.jar')
    provided files('libs/fastjson-1.1.24.jar')
    compile files('libs/lite-http-2.3.1.jar')
    provided files('libs/commons-lang-2.6.jar')
    provided files('libs/BaiduLBS_Android.jar')
    compile files('libs/Msc.jar')
    provided files('libs/android-support-v4.jar')
    compile files('libs/httpcore-4.3.2.jar')
    compile files('libs/httpmime-4.3.5.jar')
}

2.Duplicate files copied in APK META-INF/DEPENDENCIES问题

File 1: /home/bluelife/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.1/f7899276dddd01d8a42ecfe27e7031fcf9824422/httpmime-4.3.5.jar

File 2: /home/bluelife/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.1/f7899276dddd01d8a42ecfe27e7031fcf9824422/httpmime-4.3.5.jar

需要在build.gradle文件里添加如下配置:

在build.gradle中的Android节点里边添加

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/notice.txt'
    }

有的时候删除文件,重新导入或者编译一遍也可能会修复问题,具体原因未知…

2016-12-10 20:55:09 pl19920614 阅读数 3344

1.新建lib文件夹将XposedBridgeApi-xxx.jar导入其中
这里写图片描述


2.修改build.gradle->dependencies->compile files(‘lib/XposedBridgeApi-xxx.jar’)的compile为provided
这里写图片描述


3.在AndroidManifest.xml中增加三个meta-data用来标示Xposed模块以及模块信息

xposedmodule:用来标示自身是一个Xposed模块
xposeddescription:描述信息的内容
xposedminversion:所支持Xposed框架的最低版本

这里写图片描述


4.新建一个类,实现接口IXposedHookLoadPackage以及接口中的handleLoadPackage方法
这里写图片描述


5.创建assets文件夹
这里写图片描述


6.在assets文件夹中创建文件xposed_init并在其中写上实现接口IXposedHookLoadPackage类的完整路径
这里写图片描述

没有更多推荐了,返回首页