Just for start, I am not rly trying to read cell(s) from .xlsx file in Android,
I already tried almost everything what I Googled, but every time (on two different PCs, both Java 1.7.0_79) when I'm trying to build (run) this app, it ends with same error:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1
I have no idea, what more should I do, Java and Android Studio already reinstalled... Nothing. I used code from https://github.com/hmkcode/Java/tree/master/java-excel-poi
Full output from Messages
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72310Library UP-TO-DATE
:app:prepareComAndroidSupportMultidex100Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42310Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:dexDebug
trouble processing "javax/xml/stream/events/StartElement.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 2.301 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
MainActivity.java
package tona_kriz.kriziksupl;
import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.widget.Toast;
import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Workbook wb = null;
//1. Open the file
try {
AssetManager assManager = getApplicationContext().getAssets();
InputStream is = null;
try {
is = assManager.open("supl_zak.xlsx");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream caInput = new BufferedInputStream(is);
wb = new XSSFWorkbook(caInput);
int i = wb.getNumberOfSheets();
Toast.makeText(getApplicationContext(), "pocet: " + i, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "otevreno", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//2. Open a sheet
Sheet sheet = wb.getSheetAt(0);
//3. Get each cell by row & column number
Cell cell;
//Cell cell = sheet.getRow(0).getCell(0);
//double numberVal = cell.getNumericCellValue();
//System.out.println("Row: 0 - Column: 0 = "+numberVal);
//-----------------------------
cell = sheet.getRow(0).getCell(8);
String stringVal = cell.getStringCellValue();
System.out.println("Row: 0 - Column: 1 = "+stringVal);
//-----------------------------
//cell = sheet.getRow(0).getCell(2);
//Date dateVal = cell.getDateCellValue();
//System.out.println("Row: 0 - Column: 2 = "+dateVal);
//-----------------------------
//cell = sheet.getRow(0).getCell(3);
//boolean booleanVal = cell.getBooleanCellValue();
//System.out.println("Row: 0 - Column: 3 = "+booleanVal);
//-----------------------------
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tona_kriz.kriziksupl" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="#style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"> >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dexOptions {
preDexLibraries false
incremental true
javaMaxHeapSize "4g"
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "tona_kriz.kriziksupl"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:multidex:1.0.0'
compile files('libs/commons-codec-1.5.jar')
compile files('libs/dom4j-1.6.1.jar')
compile files('libs/poi-3.9.jar')
compile files('libs/poi-ooxml-3.9.jar')
compile files('libs/poi-ooxml-schemas-3.9.jar')
compile files('libs/stax-api-1.0.1.jar')
compile files('libs/xml-apis-1.0.b2.jar')
compile files('libs/xmlbeans.jar')
}
But, when I remove:
compile files('libs/commons-codec-1.5.jar')
compile files('libs/dom4j-1.6.1.jar')
compile files('libs/stax-api-1.0.1.jar')
compile files('libs/xml-apis-1.0.b2.jar')
compile files('libs/xmlbeans.jar')
the app starts, but crashes...
Logcat
http://pastebin.com/NG3AnW3z
File "supl_zak.xlsx" can be downloaded from here.
Libraries
Is there any solution for me?
Unfortunately you cannot directly use Apache POI on Android due to third party library dependencies that are pulled in. Also the size of the library causes a very big application file, which is often not possible/desirable. You even sometimes exceed limits imposed by the Dalvik Android Bytecode compilation.
There are some resources available which discuss how to get POI running on Android:
https://github.com/andruhon/android5xlsx - repackaged jars with duplicate packages in XMLBeans removed
http://blog.kondratev.pro/2015/08/reading-xlsx-on-android-4-and-hopefully.html
Apache POI with Android -- How to Create ,Read , Write, Delete PowerPoint Presentations?
The reason is that at least one the libraries (xmlbeans.jar) is declaring classes that may conflict with the core libraries that Android uses.
xmlbeans declares classes in a javax.xml package - Android also has classes in this package and other similar ones.
From the error message:
If you are legitimately using some code that happens to be in a core
package, then the easiest safe alternative you have is to repackage
that code. That is, move the classes in question into your own
package namespace.
Basically, the build tools think that you should be building a core library, but instead, you are attempting to build an application using a library which conflicts with the default Android core library. It suggests you move your code from the core package into a different package.
My advice - stop using external libraries that attempt to use core package names and use the XML functionality that Android provides.
Problem: java.exe finished with non-zero exit value 1
Solution: For solving this problem I have tried most of the solutions and hit and try again and again.
At last found the solution to this problem.
These are possible solutions you should try for solving your problem and according to me, it will definitely solve your issue.
Clean and Rebuild your Project.
Please check all the libraries are updated and gradle build version also updated.
try to increase your java heap size.
Don't use lambda expressions or syntax in your code. in my case that is the problem because I was using lambda expressions and when I was using lambda expression then it needs a declaration in build.gradle (app)file like
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
this.
it is the actual problem which I have faced please either remove this compileOptions declaration from build.gradle file or use the proper version which is compatible with your Gradle version.
Thanks
I hope this solution will help you and make your problem resolvable.
I have an idea you can follow:
some jars you import are internal API, like layoutlibs.jar, they are only involved in compiling, not packaged in apk.If you want to use them ,just create a folder named mylib in the root of the module ,then look the picture,follow them:
If my answer solve your problem ,please adopt it.
Related
I am having an issue where gradle is somehow failing to make the org.apache.logging.log4j dependencies to the application.
Below is my gradle.build file,
plugins {
id 'java'
id 'war'
}
group 'com.hf'
version '1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
compileJava {
options.compilerArgs += ["-proc:none"]
}
dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '2.11.0'
providedCompile 'org.hibernate:hibernate-core:5.3.7.Final'
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
It's seemingly straightforward. I have -proc:none because there seemed to be an issue with some deprecation otherwise. Regardless of whether proc:none is present in the gradle file, the issue persist. The output of gradle.build is as follows...
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :war UP-TO-DATE
> Task :assemble UP-TO-DATE
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
> Task :check UP-TO-DATE
> Task :build UP-TO-DATE
BUILD SUCCESSFUL in 6s
3 actionable tasks: 3 up-to-date
The dependency files are also present in the cache directory,
C:\Users\MY_USER_NAME.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j
containing the following dirs:
log4j log4j-api log4j-bom log4j-core log4j-jcl log4j-to-slf4j
all of which have the respective log4j jars nested inside them.
The problem is that eclipse does not recognize the log4j imports,
enter image description here
As a result I can't compile my simple class,
package com.hf.config;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* The Config class reduces the amount of magic strings in the application via the
* getProperty method. It has a static string CONFIG_FILE indicating the path to the config file
* which must be set manually
* #version 1.0
*/
public class AppConfig
{
static Logger log = LogManager.getLogger(AppConfig.class.getName());
private static final String CONFIG_FILE = "./app_config.txt";
/**
* Gets a property from the CONFIG_FILE corresponding to propertyName
* #param propertyName
* #return a string value corresponding to propertyName
*/
public static String getProperty(String propertyName)
{
Properties prop = new Properties();
try(InputStream inStream = AppConfig.class.getClassLoader().getResourceAsStream(CONFIG_FILE))
{
if(inStream == null)
{
log.error("config error: did not find file '" + CONFIG_FILE + "', failed to load property " + propertyName);
return null;
}
prop.load(inStream);
return prop.getProperty(propertyName);
} catch(IOException e)
{ e.printStackTrace();
}
log.error("config error: received property request '" + propertyName + "' which does not have a corresponding value in " + CONFIG_FILE);
return propertyName;
}
}
I am very new to gradle, it's something we use at work so I am trying to incorporate it as a dependency manager for my personal project to get more familiar with it. Sadly I've spent two days now trying to find a solution to this issue and am hoping someone more knowledgeable or experienced can help me resolve this. Thanks for your help in adance.
I resolved my problem by removing the project from eclipse and then re-importing it. That seems to have refreshed whatever settings were wrong and everything is working fine.
What I originally did in my frustration was install the IntelliJ IDE. When I imported my project into IntelliJ everything was working okay >___<.
That gave me the idea to remove the project from eclipse and re-import it which also fixed the problem in that IDE as well. I can only guess that gradle or eclipse were not updating the state of the project on some level.
While I'm glad to be moving passed this, I'm also rather annoyed. Hopefully this will be of some help to those running into similar issues in the future.
I'm trying to write a BitBucket Pipeline script for my repository, but so far without much luck, because Gradle seems a pain to debug.
Is there any way to show the resulting files (from compiling the jar for example) in the console when it finishes the : build task?
Preferably I'd like to see as much information as possible, rather too much than too little.
Adding logging.captureStandardOutput LogLevel.DEBUG in my build.gradle file didn't seem to do much, still getting the same output:
:compileJavaNote: -snip-\src\main\java\com\-snip-\atlas\utility\SchematicUtil.java uses or overrides a deprecated API.
Note: Recompile with -Xlint: deprecation for details.
:processResources
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 1.16 secs
Here's one way to do it (e.g. jar for a simple Java project). The build.gradle is:
apply plugin: 'java'
jar {
doLast {
new File("${buildDir}/libs").eachFileRecurse { file ->
println "TRACER: ${file.getAbsolutePath()}"
}
}
}
It should be straight-forward to tailor for other needs.
My team and I develop Android apps and have decided on coding guidelines that all should follow. I therefore started implementing custom lint rules which can be found here, and have added it to our automated build process in Jenkins.
The problem we are now having is that these rules no longer work after upgrading our Android projects from
'com.android.tools.build:gradle:2.2.0' to
'com.android.tools.build:gradle:2.3.0'
We continually get the error:
java.lang.NoSuchMethodError: com.android.tools.lint.detector.api.JavaContext.getContents()Ljava/lang/String;
When switching back to gradle 2.2.0 all is fine, the custom rules are checked and the app builds.
I tried updating gradle in the lint repository and unfortunately have the exact same issue in my TodoDetector at line 72. In Android studio all dependencies are resolved fine, but when trying to build and deploy the library with ./gradlew clean build test install, We get the error listed above.
I've been searching all day and have yet to find a viable solution for this problem. Any help, tips or advice is greatly appreciated.
Terminal output
:clean
:aarWrapper:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
:check
:build
:aarWrapper:preBuild UP-TO-DATE
:aarWrapper:preDebugBuild UP-TO-DATE
:aarWrapper:checkDebugManifest
:aarWrapper:prepareDebugDependencies
:aarWrapper:compileDebugAidl
:aarWrapper:compileDebugNdk UP-TO-DATE
:aarWrapper:compileLint
:aarWrapper:copyDebugLint UP-TO-DATE
:aarWrapper:mergeDebugShaders
:aarWrapper:compileDebugShaders
:aarWrapper:generateDebugAssets
:aarWrapper:mergeDebugAssets
:aarWrapper:mergeDebugProguardFiles UP-TO-DATE
:aarWrapper:packageDebugRenderscript UP-TO-DATE
:aarWrapper:compileDebugRenderscript
:aarWrapper:generateDebugResValues
:aarWrapper:generateDebugResources
:aarWrapper:packageDebugResources
:aarWrapper:processDebugManifest
:aarWrapper:generateDebugBuildConfig
:aarWrapper:processDebugResources
:aarWrapper:generateDebugSources
:aarWrapper:incrementalDebugJavaCompilationSafeguard
:aarWrapper:javaPreCompileDebug
:aarWrapper:compileDebugJavaWithJavac
:aarWrapper:processDebugJavaRes UP-TO-DATE
:aarWrapper:transformResourcesWithMergeJavaResForDebug
:aarWrapper:transformClassesAndResourcesWithSyncLibJarsForDebug
:aarWrapper:mergeDebugJniLibFolders
:aarWrapper:transformNativeLibsWithMergeJniLibsForDebug
:aarWrapper:transformNativeLibsWithStripDebugSymbolForDebug
:aarWrapper:transformNativeLibsWithSyncJniLibsForDebug
:aarWrapper:bundleDebug
:aarWrapper:compileDebugSources
:aarWrapper:assembleDebug
:aarWrapper:preReleaseBuild UP-TO-DATE
:aarWrapper:checkReleaseManifest
:aarWrapper:prepareReleaseDependencies
:aarWrapper:compileReleaseAidl
:aarWrapper:compileReleaseNdk UP-TO-DATE
:aarWrapper:copyReleaseLint UP-TO-DATE
:aarWrapper:mergeReleaseShaders
:aarWrapper:compileReleaseShaders
:aarWrapper:generateReleaseAssets
:aarWrapper:mergeReleaseAssets
:aarWrapper:mergeReleaseProguardFiles UP-TO-DATE
:aarWrapper:packageReleaseRenderscript UP-TO-DATE
:aarWrapper:compileReleaseRenderscript
:aarWrapper:generateReleaseResValues
:aarWrapper:generateReleaseResources
:aarWrapper:packageReleaseResources
:aarWrapper:processReleaseManifest
:aarWrapper:generateReleaseBuildConfig
:aarWrapper:processReleaseResources
:aarWrapper:generateReleaseSources
:aarWrapper:incrementalReleaseJavaCompilationSafeguard
:aarWrapper:javaPreCompileRelease
:aarWrapper:compileReleaseJavaWithJavac
:aarWrapper:processReleaseJavaRes UP-TO-DATE
:aarWrapper:transformResourcesWithMergeJavaResForRelease
:aarWrapper:transformClassesAndResourcesWithSyncLibJarsForRelease
:aarWrapper:mergeReleaseJniLibFolders
:aarWrapper:transformNativeLibsWithMergeJniLibsForRelease
:aarWrapper:transformNativeLibsWithStripDebugSymbolForRelease
:aarWrapper:transformNativeLibsWithSyncJniLibsForRelease
:aarWrapper:bundleRelease
:aarWrapper:compileReleaseSources
:aarWrapper:assembleRelease
:aarWrapper:assemble
:aarWrapper:lint FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':aarWrapper:lint'.
> com.android.tools.lint.detector.api.JavaContext.getContents()Ljava/lang/String;
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
gradle file
apply plugin: 'java'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}
repositories {
jcenter()
}
allprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
dependencies {
compile 'com.android.tools.lint:lint:24.3.1'
compile 'com.android.tools.lint:lint-api:24.3.1'
compile 'com.android.tools.lint:lint-checks:24.3.1'
testCompile 'junit:junit:4.11'
testCompile 'org.assertj:assertj-core:3.0.0'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'com.android.tools.lint:lint:24.3.1'
testCompile 'com.android.tools.lint:lint-tests:24.3.1'
testCompile 'com.android.tools:testutils:24.3.1'
}
jar {
baseName 'com.bignerdranch.linette'
version '1.0'
manifest {
attributes 'Manifest-Version': 1.0
attributes('Lint-Registry': 'com.bignerdranch.linette.registry.CustomIssueRegistry')
}
}
sourceSets {
main {
java {
srcDirs = ["lint/src/main/java"]
}
}
test {
java {
srcDirs = ["lint/src/test/java"]
}
}
}
configurations {
lintChecks
}
dependencies {
lintChecks files(jar)
}
defaultTasks 'assemble'
task install(type: Copy) {
from configurations.lintChecks
into System.getProperty('user.home') + '/.android/lint/'
}
aarWrapper gradle
apply plugin: 'com.android.library'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName '1.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
project.afterEvaluate {
def compileLint = project.tasks.getByPath(':aarWrapper:compileLint')
compileLint.dependsOn parent.tasks.getByName("jar")
compileLint << {
copy {
from '../build/libs'
into 'build/intermediates/lint'
}
}
}
If your deactivation of instant run not works then add it on your build.gradle file.
android {
lintOptions {
// if true, stop the gradle build if errors are found
abortOnError false
}
}
Then clean your project and run.
if abortOnError false not resolve your issue, then you can try the following
lintOptions {
checkReleaseBuilds false
}
Hope it will solve your issue.
Resource Link:
https://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de442315b5ff1ada819c7
gradle build fails on lint task
Daniel Passos has given a solution here in this tutorial
Ignoring Erros
Lint is part of Gradle build process, by default if it fail your build will stop and you will get a message like it:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.
In 99% of the cases people will start ignore lint instead of fix the problems, adding this on build.gradle app
lintOptions {
abortOnError false
}
But IMHO it’s wrong. If lint is telling, you have a problem the best thing to do is fix it. Lint is a tools to make your app and the UX better.
Ignoring specific erros
Sometimes you really need to ignore some lint errors. For example, when you are using webView.getSettings().setJavaScriptEnabled(true); in your WebView
In this case, you should disable only the specific ids instead of disabling the whole lint.
lintOptions {
disable 'SetJavaScriptEnabled'
}
You also can ignore it directly in your code:
#SuppressLint "SetJavaScriptEnabled")
Or in your XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="SomeLintIssueIdHere" >
If you prefer you can move all your issues rules from a lint.xml file in the root directory of your project.
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="SetJavaScriptEnabled" severity="ignore" />
</lint>
I was trying out the same code and bumped into the same issue.
There are new versions available for com.android.tools.lint. Try 25.2.0 or above, and you will notice that the example code TodoDetector uses deprecated methods.
Basically, you need to make your class implement Detector.JavaPsiScanner instead of Detector.JavaScanner.
http://static.javadoc.io/com.android.tools.lint/lint-api/25.3.0/com/android/tools/lint/detector/api/Detector.JavaPsiScanner.html
I had the same error when migrating to Android Gradle plugin 2.3.0 com.android.tools.build:gradle:2.3.0. The problem in my case was that the android-apt plugin that I used has become deprecated: Android Gradle plugin 2.3.0 has annotation processing out of the box and seems to block android-apt.
Read the migration guide and migrate the "apt" section of your gradle build script and "apt" dependencies, then remove the android-apt plugin:
https://bitbucket.org/hvisser/android-apt/wiki/Migration
UPD: The problem was still there after the fix above. I looked into the error stacktrace in Event Log and found out that the exception happens in one of my custom lint checkers (io.vokal.lint:todo:1.0.3). Removing it from ~/.android/lint solved the problem.
I encountered the same issue. Looking into context.getContents():
return mDriver.getClient().readFile(file);
So i tried to do it manually like this: context.getDriver().getClient().readFile(context.file) which throws the same error message.
My workaround now is, instead of using context.getContents() i just use context.file and read it out without the driver. I am not sure if this is a good way but for me it works.
So here the working code:
static void someMethod(com.android.tools.lint.detector.api.Context context){
readFile(context.file)
...
}
static String readFile(File file) {
String path = file.getAbsolutePath();
Charset encoding = Charset.defaultCharset();
try {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
} catch (IOException e){
return "";
}
}
I am using Comriva library to extract MFCC features to my speech recognition project. And i have imported the comriva core packages to my project. When i tired to build it im getting this error in gradle,
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72220Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:collectDebugMultiDexComponents UP-TO-DATE
:app:packageAllDebugClassesForMultiDex UP-TO-DATE
:app:shrinkDebugMultiDexComponents UP-TO-DATE
:app:createDebugMainDexClassList UP-TO-DATE
:app:dexDebug
trouble processing "javax/xml/stream/events/StartElement.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 5.524 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
I didn't include any xml libraries so far like simple-xml.
This is my gradle.build file,
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "info.androidhive.sleepApp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile files('libs/jl1.0.jar')
compile files('libs/commons-logging-api.jar')
compile files('libs/cp.jar')
compile files('libs/http-2.2.1.jar')
compile files('libs/jama-1.0.2.jar')
compile files('libs/jl1.0.jar')
compile files('libs/jogg-0.0.7.jar')
compile files('libs/lucene-analyzers-3.0.0.jar')
compile files('libs/lucene-core-3.0.0.jar')
compile files('libs/lucene-queries-3.0.0.jar')
compile files('libs/lucene-queryparser-3.0.0.jar')
compile files('libs/lucene-snowball-3.0.3.jar')
compile files('libs/jorbis-0.0.15.jar')
compile files('libs/mdsj.jar')
compile files('libs/tritonus_remaining.jar')
compile files('libs/tritonus_share.jar')
compile files('libs/wstx-lgpl-3.0.1.jar')
compile files('libs/weka-stable-3.6.13.jar')
compile files('libs/stax-api-1.0.jar')
compile files('libs/mp3spi1.9.4.jar')
}
Please help me to overcome this problem.
I figured out the issue it was the stax-api-1.0.jar this included the javax.xml.stream.events.* classes after removing the jar i was able to build it successfully. This jar came with the comriva that is why i didn't notice it.
I am actually using the newly released Gradle 2, but having the same issues as described in the previous post.
I am also a newb trying to follow the example given in the Spring guide (http://spring.io/guides/gs/gradle/#scratch) but after my first compile, there were no classes.
I have tried various configurations of tree structure including adding the structure and code suggested in the above thread:
"I guess the source file path is src/org/gradle/example/simple/HelloWorld.java. (The diagram shows something different.) That doesn't match Gradle's default, so you'll have to reconfigure it: sourceSets.main.java.srcDirs = ["src"] – Peter Niederwieser Dec 7 '12 at 1:23 "
adding the line: sourceSets.main.java.srcDirs = ["src"] allows the code to compile, however, I still have no classes.
Here is the successful build.
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
BUILD SUCCESSFUL
Total time: 4.468 secs
Here is the build file:
apply plugin: 'java'
sourceSets.main.java.srcDirs=["src"]
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "joda-time:joda-time:2.2"
}
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
task wrapper(type:Wrapper) {
gradleVersion = '1.11'
}
apply plugin: 'application'
mainClassName = 'hello.HelloWorld'
Where are my classes? Please help.
After I got stuck with the same problem, I hacked around for a bit before I understood the reason for this behavior.
My project structure was like so
MyProject
- src
- main
- java
- hello
HelloWorld.java
build.gradle
The problem was that the build.gradle is supposed to be under the Project-Root folder i.e. MyProject and not under the hello folder !!!
Changed it so that my Project structure looks like below, ran the gradle build and saw that classes folder was created:
MyProject
- src
- main
- java
- hello
HelloWorld.java
build.gradle
When you think about it, the build.gradle is used to build the complete project and not just the classes within one folder and should rightfully sit under the project-root folder.