您的位置:首页 > 运维架构 > Linux

Linux下使用Gradle编译Android工程时遇到的问题及解决方法

2016-03-25 17:39 1246 查看

一)Android Gradle插件相关问题

> Plugin with id'com.android.library' not found.
解决方法:http://stackoverflow.com/questions/18153739/android-studio-plugin-with-id-android-library-not-found
Instruct Gradle todownload Android plugin from Maven Central repository.

You do it by pasting the following code at the beginning of theGradle build file:

buildscript {

    repositories {

        mavenCentral()

    }

    dependencies {

        classpath 'com.android.tools.build:gradle:1.1.1'

    }

}


Failed to apply plugin [id'com.android.library']
   > Gradle version 2.2 is required. Currentversion is 2.12. If using the gradle wrapper, try editing the distribution Url in .../leakcanary-master/gradle/wrapper/gradle-wrapper.properties togradle-2.2-all.zip
解决方法:
http://stackoverflow.com/questions/29346593/gradle-version-1-10-is-required-current-version-is-2-2-1-in-android
需要更新一下Android的Gradle插件与2.12匹配,
将原来的:
  buildscript {
    repositories {
      mavenCentral()
    }
    dependencies {
      classpath'com.android.tools.build:gradle:1.2.3'
改为1.5.0
    }
  }

二)aapt相关问题

在Linux系统中使用如下命令编译工程leakcanary(下载地址: https://github.com/square/leakcanary):
gradle assemble或./gradlew assembleDebug,出现如下问题:

Execution failed for task':leakcanary-watcher:processReleaseResources'.

>com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException: Process 'command'.../android-sdk-linux/build-tools/21.1.2/aapt''finished
withnon-zeroexitvalue 1

使用./gradlewassembleDebug --info显示更详细的信息如下:

Command:.../software/android-sdk-linux/build-tools/21.1.2/aaptpackage -f --no-crunch -I .../software/android-sdk-linux/platforms/android-21/android.jar-M .../leakcanary-master/leakcanary-watcher/build/intermediates/bundles/release/aapt/AndroidManifest.xml-S
.../leakcanary-master/leakcanary-watcher/build/intermediates/bundles/release/res-A .../leakcanary-master/leakcanary-watcher/build/intermediates/bundles/release/assets-m -J .../leakcanary-master/leakcanary-watcher/build/generated/source/r/release--custom-package
com.squareup.leakcanary.watcher --non-constant-id -0 apk--output-text-symbols .../leakcanary-master/leakcanary-watcher/build/intermediates/bundles/release
Successfullystarted process 'command '.../software/android-sdk-linux/build-tools/21.1.2/aapt''
Unknown source file : .../software/android-sdk-linux/build-tools/21.1.2/aapt:/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not
found (required by .../software/android-sdk-linux/build-tools/21.1.2/aapt) 
Unknown source file : .../software/android-sdk-linux/build-tools/21.1.2/aapt:/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not
found (required by .../software/android-sdk-linux/build-tools/21.1.2/aapt) 
Unknown source file : .../software/android-sdk-linux/build-tools/21.1.2/aapt:/usr/lib/libz.so.1: no version information available (required by .../software/android-sdk-linux/build-tools/21.1.2/aapt)
可以看到是libstdc版本太低引起的。关于`GLIBCXX_3.4.11' not found问题的解决方法,可以参考官方文档,https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.how_to_set_paths  



我选择了重新安装最新的GCC,

源码安装GCC
下载地址:http://120.52.72.55/ftp.tsukuba.wide.ad.jp/c3pr90ntcsf0/software/gcc/releases/gcc-5.3.0/
下载gcc-5.3.0.tar.gz后解压

mkdirgccbuilddir
cd gccbuilddir gccsrcdir
gccsrcdir/configure --prefix=destdir --other-opts...

make

make check

make install

根据提示在ftp://gcc.gnu.org/pub/gcc/infrastructure 或h
4000
ttp://ftp.tsukuba.wide.ad.jp/software/gcc/infrastructure/下,下载gmp,mpfr,mpc等。解压后放到gccsrcdir目录下,重新运行即可。

关于该问题的解决方案,请参考http://blog.csdn.net/lufqnuli/article/details/50963525。

dpkg --add-architecture i386

    apt-get update

    apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386
也没有解决问题。

在运行configure命令时,发生如下错误:
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options tospecify their locations. Source code for these libraries can be found at their respective hosting sites as well as at ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also http://gcc.gnu.org/install/prerequisites.htmlfor additional info.  If you obtained GMP, MPFR and/or MPC from a vendor distribution package,make
sure that you have installed both the libraries and the header files.  They may be located in separate packages.
在make时,发生如下错误:

Entering directory `.../opt/gcc-5.3.0/build/x86_64-unknown-linux-gnu/libgcc'

../../../libgcc/config/t-softfp:106: 在“else”指令之后含有不该出现的文字

安装最新的gcc后,上述问题仍然没有解决。

QueuedCruncheris using .../android-sdk-linux/build-tools/23.0.2/aapt
java.io.IOException:Cannot run program"/home/luye/software/android-sdk-linux/build-tools/21.1.2/aapt":error=2, 没有那个文件或目录
事实上,aapt是存在的,
网上的这个方法:

http://stackoverflow.com/questions/30111443/android-studio-fails-to-build-new-project-timed-out-while-wating-for-slave-aapt
也没有解决问题。 
 
最后根据 http://www.phperz.com/article/14/1212/40796.html中的方法解决,工程成功编译。

错误描述:

在64位Debian上运行Android sdk目录下的adb和aapt提示: bash: ./aapt: No such file or directory

原因分析:

原因是Android sdk的文件都是在32位的库编译的,在64位系统上无法找到对应的库。

解决方法:

首先执行 : sudo apt-get install lib32stdc++6

此时可以看到adb顺利运行了,但是aapt还是无法运行提示error while loading shared libraries: libz.so

此时执行: sudo apt-get install lib32z1 lib32z1-dev

运行aapt,问题解决.

补充解决工程中整理的其他解决方法,虽然跟我遇到的问题不一样:

解决方案:http://www.bubuko.com/infodetail-986662.html

 

21.1.2/aapt
‘‘finishedwithnon-zeroexitvalue 42

问题的主要原因是因为资源文件解析错误。
常见的原因有

  1.资源文件名冲突

    这个换个文件名就可以了

  2.引用包重复

    Android studio 下面有了v4包或者v7包,这个时候在libs下又添加了一次包,就会报这个错误,删掉Libs下重复的包就行了。

  2.文件名显示的格式与文件本身的格式不对应

    这个比较难发现,重新换个正确的文件就可以了。

 

解决方案:http://www.ithao123.cn/content-8149921.html

最近使用Android Studio导入Eclipse工程后,常遇到如下的报错:
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException:  Process 'command 'C:UsersVishnu RuhelaAppDataLocalAndroidsdkbuild-tools
21.1.2aapt.exe''finishedwithnon- zero exitvalue 1
这种莫名其妙的问题真心毁了我的三观,,好在经过不断努力和尝试还是解决了。
解决方法:
一、修改应用launcher icon的引用方式
即从drawable改为mipmap: 
右键res->New->Android resoursedirectory->选择mipmap,第一步; 
右键mipmap->New->Image Asset,完成剩下的操作。
二、修改manifest
1、修改android:icon的”@drawable/ic_launcher”为”@mipmap/ic_launcher” 

2、在application中添加tools:replace=”android:icon”,参见如下代码:
<application        android:allowBackup="true"        tools:replace="android:icon"         android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"         android:theme="@style/AppTheme">
如果tools标红,manifest标签中增加xmlns:tools=”http://schemas.android.com/tools”即可。
问题的具体原因无从做更深入分析,但是这样操作既符合新应用规范,又解决了我的棘手问题。
解决方案:http://blog.csdn.net/serapme/article/details/46685557

原问题情景:由于项目工程特别大,在编译一段后就会报下面这个错误:

Error:Execution failed
for
task
':dexAppDebug'
.

> com.android.ide.common.
process
.ProcessException: org.gradle.
process
.internal.ExecException:

>  Process
'command '
C:Program FilesJavajdk1
.8.0
_25
in
java.exe
''
finished
with
non-
zero
exit
value1[/code]
在stackOverFlow上找了很多办法尝试都行不通,于是只能自己琢磨着不断尝试,最后在任务管理器中观察到studio.exe和java.exe运行时占用内存量较大,又考虑 
电脑配置可能不够用,所以开始不断尝试修改占用内存相关的东西,并终于取得了进展。关键代码是build.gradle中的:

dexOptions {

    javaMaxHeapSize
"xx"[/code]
}

xx为合理的内存大小。如果你也遇到了这种问题,不妨试试~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: