I had posted a previous question and ask this in the comments, but received no response. I have been struggling with finding a solution to this for a couple weeks now.
I am trying to add .jar files to my program for uploading a document in an android app. However, it says gradle was unsuccessful and it could not find property 'file'.
Here is the error:
Error:(25, 0) Could not find property 'file' on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#41762346.
Here is the code
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.ashleygreen.healthcareapp"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile file 'libs/httpclient-4.2.2.jar.zip'
compile file 'libs/httpmime-4.0.jar.zip'
}
Firstly, Gradle cannot work with zipped jar files - you'll have to unzip the jar files first.
When you include the line
compile fileTree(dir: 'libs', include: ['*.jar'])
This means that any file ending in .jar will be included as a dependency as long as it is in the libs directory. Therefore there is no need to use either of the last lines (as those libraries are already included via the first line).
However, if you did want to include a single jar file from another directory, you're missing the parentheses after file:
compile file('libs/httpmime-4.0.jar')
I faced the same error. However, the following worked for me (in android studio 1.5):
compile files ('libs/httpclient-4.2.2.jar.zip')
compile files('libs/httpmime-4.0.jar.zip')
Notice it's files with an extra 's' with parentheses. Only file is not recognized.
Related
I want to hide real code from aar file. My library's Gradle file looks like this.
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
}
And I am getting following exception while running this app.
Warning:Exception while processing task java.io.FileNotFoundException: E:\MyProjects\TestApp\testLibrary\build\intermediates\proguard-rules\release\aapt_rules.txt (The system cannot find the path specified)
Error:Execution failed for task ':testLibrary:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details
If I changed the minifyEnabled true to minifyEnabled false then this app runs without fail but I can see the Java files from generated arr file.
So I want to hide Java code.
for a library you should not supply proguard-rules.pro but some proguard-consumer-rules.pro... which contains the configuration rules, which are being applied, when the library is compiled into an APK package (contrary to the usual behavior, when the library is being build).
// These rules will be applied when a consumer of this library sets 'minifyEnabled true'.
consumerProguardFiles 'proguard-consumer-rules.pro'
the library is not directly being obfuscated like that, but only later on - without having every single consumer of the library having to define their own ProGuard rules configuration. see the question I've linked above, one of it's answers provides a basic configuration, in order to keep the public methods (so that one can still use the library, once it had been merely obfuscated).
and also see the Android Testing template for: module-android-library.
I would assume, that this AAPT error stems from supplying an empty ProGuard configuration file.
I have an android application that used kinvey and it worked just fine with me suddenly i got
java.lang.OutOfMemoryError: GC overhead limit exceeded
so i put
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
in my gradle file but then i got java.lang.NoClassDefFoundError in the line when i create new client
mKinveyClient = new Client.Builder(AP_ID,App_Secret, this).build();
i tried to clean project ,clean gradle file , updated my kinvey sdk from 1.5 to 1.6 Any suggestions?
here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
dexOptions { //for the error java.lang.OutOfMemoryError: GC overhead limit exceeded
incremental true
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.example.dell.augmentedreality"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
flatDir {
dirs 'libs'
}
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile files('src/main/java/Vuforia.jar')
compile(name:'kinvey-android-2.10.6', ext:'aar') {changing= true}
compile 'com.android.support:multidex:1.0.0'
compile 'com.gordonwong:material-sheet-fab:1.2.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
///////////////////////////for animating the text
///////////////////////
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
///////////////google cloud messaging
compile 'com.google.android.gms:play-services:8.4.0'
}
Edit:in the image below my jars files
I think the problem is that you copied both the kinvey JAR file and the AAR file into the libs/ folder. You only need the AAR.
The class that is claimed to be missing, com.google.api.client.json.JsonObjectParser, is contained within google-http-client-1.19-0.jar, so adding that JAR file to the correct libs/ directory in the module and including these lines in you build.gradle should properly find that class without error.
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name:'kinvey-android-*', ext:'aar')
// other stuff
}
With regards to the OutOfMemory error, you most likely exceeded the Android Dex method limit because of how many dependencies you've included. Most specifically, the last line of your gradle file for the play-services dependency. If you read that documentation, you'll see the note that says
Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them.
Since you seem to only want cloud messaging, you can just include that one, so replace this line.
compile 'com.google.android.gms:play-services:8.4.0'
With this one
compile 'com.google.android.gms:play-services-gcm:8.4.0'
And any other Play Services you want to include.
i got java.lang.NoClassDefFoundError
You have included wrong Dependant jar. Add appropriate Dependant version of jar by using maven or gradle.
I am currently trying to build an android studio project using a dependency from the openimaj Java library.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.mapinguari.myapplication"
minSdkVersion 15
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'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'org.openimaj:openimaj:1.3.1'
}
Is my module build file. It reports no errors when syncing to the IDE.
However when I try to construct any of the classes in one of the source files the Android Studio does not recognize any of the classes from the openimaj dependency.
Any Help much appreciated.
Thank you!
I think it might be because you've specified a non-jar OpenIMAJ dependency (specifically you've told it to link against the OpenIMAJ master pom file, which only contains references to the different sub-modules). You probably need to actually choose the specific modules that you want - for example if your application is doing image processing, then add the dependency org.openimaj:image-processing:1.3.1.
Edit:
It seems that the batik svg libraries have a circular dependency somewhere that breaks Gradle (see https://issues.apache.org/jira/browse/BATIK-1098). This is what causes an eventual StackOverflowError. Additionally, something is pulling in xml-apis which will conflict with Android. Assuming you don't mind not have SVG image support, then the following should work:
repositories {
mavenCentral()
maven {
url "http://maven.openimaj.org"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:18.+'
compile('org.openimaj:image-processing:1.3.1') {
exclude group: 'org.apache.xmlgraphics'
exclude group: 'xml-apis'
}
}
You might also want to add additional exclusions for dependencies that are not needed in your app - it seems that just including org.openimaj:image-processing pulls in lots of things that are almost certainly not going to be needed (I've created an issue for that here: https://github.com/openimaj/openimaj/issues/97).
I am trying to add the this jar file to my Android Studio project:
I did the necessary steps to add the jar as 'library'. But build gives me the following error:
Error:error reading C:\Users\Malik\AndroidStudioProjects\test6\app\libs\imageviewtouch.jar; error in opening zip file
tion timeout.)
Re-download dependencies and sync project (requires network)
Re-download dependencies and sync project (requires network)
I tried adding another jar file I downloaded from somewhere and that didn't give the error.
Is this jar file corrupted or am I missing a dependency?
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.greenbergc.test6"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile files('libs/about-0.2.1.jar')
compile files('libs/imageviewtouch.jar')
}
I tried to add this jar file and successfully added without any error. I don't know how you add this file. This is the process that I use to add this jar file :
Downloaded this project from github.
Extract the project and get jar file from libs folder.
Now inside my project's libs folder, I simple paste this jar file.
In android studio, go to libs folder -> right click on imageviewtouch jar file -> add as library.
Done
I need to use the commons-codec-1.9.jar from the commons-codec-1.9 library supplied by Apache. I've used this as a library in another project in NetBeans, so I already had the required .jar file that I needed to import. I copied the jar file from the NetBeans project and put it in my app project (app:libs folder) and right-clicked and chose the "Add as library..." option. I added it to my project dependencies as well via File > Project Structure > Dependencies. I created the import for the library in the classes I've written that use the library, and I get no errors and the code builds. However, when I run the app, it breaks and throws a NoSuchMethod exception... even though it is there.
Here are the contents of my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.example.<path_stuff>"
minSdkVersion 17
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/commons-codec-1.9.jar')
}
Here is my settings.gradle
include ':app'
I have also recently been getting a build error after I removed the commons-codec stuff from the libs folder and tried to re-add it. The error says something along the lines of "Build failed: could not find task 'assemble' in project " as if Android Studio thinks this is another project. Can someone please help me understand what is going on here and where I am going wrong?
No such method error details:
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String
Edit: Realized I included the incorrect build.gradle file. Updated settings.gradle to remove the include statement. Included correct build.gradle and NoSuchMethod error.
Remove include ':libs:commons-codec-1.9: from your settings.gradle.
Add compile fileTree(dir: 'libs', include: '*.jar') to your dependencies block in your module's build.gradle file.
android {
...
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will automatically compile any .jar file in your libs folder into your project.