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
Related
Any project in my android studio fails to build.The error message is as follows-
Gradle sync failed: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-3.3-all.zip'.
Consult IDE log for more details (Help | Show Log)
Moreover i'm unable to make a new java class in android studio by File->new->Java class as no such option is available. I found some answers saying right click on java folder then clicking Mark Directory as -> SOurce root, even this option is not there . Moreover, for resolving the gradle issue, i found some answers saying click File->Invalidate Caches/Restart and delete the .gradle file in home directory then update android studio, i did accordingly but still nothing works.
build.gradle contents are-
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.android.iitmandi"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
testCompile 'junit:junit:4.12'
}
Contents of gradle-wrapper.properties are-
#Tue Mar 28 20:10:53 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Build.grale-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
on doing Build->Clean project this error message was shown-
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugUnitTestApkCopy'.
> Could not resolve junit:junit:4.12.
Required by:
project :app
> Could not resolve junit:junit:4.12.
> Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> Connect to jcenter.bintray.com:443 [jcenter.bintray.com/108.168.243.150] failed: Connection timed out
I even uninstalled Android-Studio 2.3 and installed 2.2.2 instead but still the problem persists
the code in JUnit library is referenced in the project but there is no related JUnit dependent library yet...you either have to delete the referencing line(s) of code in the gradle or install the JUnit library.For more info https://debugah.com/failed-to-resolve-junitjunit4-12-how-to-solve-11544/
I have imported a android source code from Github and while syncing the gradle process I have got an error
Error:(1, 0) Plugin with id 'com.android.application' not found.
Open File
This is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "activities.safepassbeta"
minSdkVersion 16
targetSdkVersion 19
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 'com.android.support:support-v4:20.0.0'
}
Try changing the classpath in the top level build.gradle file to 'com.android.tools.build:gradle:2.0.0-beta7' and the distributionUrl value in gradle-wrapper.properties file to https://services.gradle.org/distributions/gradle-2.10-all.zip.
Make sure that in the settings for gradle in the 'Build, execution and deployment' section, you have set the preference to 'Use default gradle wrapper'.
As the other answer described, try changing the classpath in the top level build.gradle file. The file you show is the application build.gradle, not the top level build.gradle file. For Android Studio 3, you can try using 'com.android.tools.build:gradle:3.0.1'. The problem is that the gradle dependency is not downloading properly, usually because of improper settings for the url to use to download gradle. This is a common problem. If the problem persists look into solutions for how to set up gradle, such as Manually install Gradle and use it in Android Studio
A quick-and-easy fix is to look at your previous projects which work on your IDE, look at what version of gradle they are using. If you use that version of gradle in this project it will most likely work.
However, the 'proper' solution is to set up the distributionUrl properly. Worst come to worst, if that does not work, you could also try manually downloading Gradle to use it in your project.
Summary:
I have an AAR file that depends on a JAR file, when I build the AAR project, it doesn't contain the JAR code.
Details:
I have a Java SDK library project that contains code that we use for Java web projects and such, this library is created using Gradle and resides in an internal nexus server (as a JAR).
The goal is to provide an "Android configured" version of this JAR library through an AAR library that multiple Android Applications can use and minimize the effort (and boilerplate code) to implement it. This AAR file is also uploaded to the nexus server to be used by the Android Application projects.
My AAR project includes a gradle dependency for my Java SDK library (the JAR) but when built, the AAR doesn't include any classes from it.
Code:
This is the Java SDK project's gradle file:
apply plugin: 'java'
//noinspection GroovyUnusedAssignment
sourceCompatibility = 1.7
version = '1.1.1'
repositories {
mavenCentral()
}
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'org.springframework:spring-web:3.1.1.RELEASE'
compile 'com.google.code.gson:gson:2.3'
}
This is the gradle file for my AAR Project, note that I removed the Maven repository declarations to my nexus server from it. I guess it shouldn't matter for the sake of this question.
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "2.2.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile ('com.mycompany:javasdk:1.1.1')
}
This is the gradle file for my Android Project, again I removed the nexus server references:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.mycompany.application1"
minSdkVersion 16
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.mycompany:androidsdk:2.2.2#aar')
}
NOTE: I initially solved the issue by adding the JAR in the lib directory of the AAR project, but this is undesired. It makes having a nexus server useless. It would be good that we can just bump the JAR's version number in the AAR project's gradle file and the update happens automatically at compile time.
NOTE2: I tried adding transitive=true to my AAR dependency in the Android Project but it didn't solved anything, the real issue is that when building the AAR project, the JAR project code doesn't get bundled.
You can add this task:
task copyLibs(type: Copy) {
from configurations.compile
into 'libs'
}
Dependencies will be downloaded from your Nexus, but when you need package the library, execute this task first and jar files will be copied and included inside final aar.
By default, AAR does not include any dependencies. Solution mentioned by #Hector should work for gradle plugin < 3.0. For Gradle plugin 3.0+, try custom config as mentioned here.
android { ... }
// Add a new configuration to hold your dependencies
configurations {
myConfig
}
dependencies {
....
myConfig 'com.android.support:appcompat-v7:26.1.0'
myConfig 'com.android.support:support-v4:26.1.0'
...
}
task copyLibs(type: Copy) {
from configurations.myConfig
into "libs"
}
None of the suggestions helped me for Gradle 4.6, so I wasted the whole day inventing my own.
Eventually I found a good Gist and modified it for my version of Gradle:
https://gist.github.com/stepio/824ef073447eb8d8d654f22d73f9f30b
The upper ones didn't work for me in android tools 3.6.2 with Gradle. 5.6.1 . For anyone having the same issue, using https://github.com/kezong/fat-aar-android in the end worked fine for me.
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.
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.