I am facing a horrified error. After installing android studio 2.2.3, i couldn't build my very first project due to gradle error. I even tried using maven link but i use my PC offline. The following is my gradle script:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.samim.myapplication"
minSdkVersion 17
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 {
androidTestCompile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile 'com.android.support:appcompat-v7:25.1.1'
testCompile 'junit:junit:4.12'
}
I am also posting an image regarding the errors.
After doing clean build and rebuild
project gradle
I tried using maven link but i use my PC offline
That's your problem.
Gradle uses the exact same sources as Maven would.
Once you get online, your dependencies should resolve from any "New Project" in Android Studio. You then should let the dependencies download, and then you are welcome to work offline.
Note: You also need to download the Android SDK
The best solution is to add untrusted server certificates automatically to android studio when using the internet from workplace. Go to Settings -> Tools -> Server Certificates, now check "Accept non-trusted certificates automatically". After this coding can be done offline.
Also using a third party VPN solves certificate issues.
Related
I came across a problem while implementing an Android plugin for Unity based on EasyPermissions. The issue was due to
Caused by: java.lang.ClassNotFoundException: Didn't find class "pub.devrel.easypermissions.EasyPermissions$PermissionCallbacks"
as the relevant classes were not packed by Android Studio into my AAR file.
I tried various ways:
Just compile in Android Studio and hope the resulting AAR will be fine FAIL
Download an AAR from jCentral and add it to Unity - FAIL
So finally I unzipped the EasyPlugin AAR and took the classes.jar file thats inside and added this to Unity. This worked. Yet its quite a manual process.
What is the tinly little bit I need to add to my gradle file to get this done automatically?
I am using:
https://github.com/googlesamples/easypermissions
Unity 2017.1 (should not matter)
Android Studio 2.3.3
Gradle task used: build->assemble
My Gradle File:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "27.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
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(include: ['*.jar'], dir: 'libs')
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:26.+'
testCompile 'junit:junit:4.12'
compile 'pub.devrel:easypermissions:1.0.1'
provided files('unity/classes.jar')
}
PS. There was a second issue when overriding UnityPlayerActivity but for that a clause provided instead of compile was the solution.
Check above comments.
If you use an external library its enough to add its AAR into Plugins/Android directory in Unity.
For some reason I added it in a way that went unnoticed by Unity and Unity was not adding it into resulting APK file.
I Have started my new android project with Basic Default Activity.IT run fine in emulator .I Have tried to install iy in real device both pre lolipop and abovr lolipop device but getting error
App cannot be installed error in prelolipop device and above lolipop device app will install but when i try to open app it will close
Can any one help how to fix this issue ?
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.myapp.myapplication"
minSdkVersion 14
targetSdkVersion 26
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:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
Your code is fine, my guess is that your APK is not completely built
Build your APK:
On Android Studio click on Build
Then click on Build APK(s)
After that search for your debug APK and install it on your device
If this fails you can try ADB, take a look at the following guides for install and usage:
How to install it on windows
How to Install apk using ADB
Hope it helps
Two things could be the problem.
Navigate to settings > security and make sure Unknown sources is checked.
Make sure you downloaded the whole apk in the email
Hope this helps!
So, the title pretty much sums up my problem. Anyone know how to fix it? Last time I build apk, it work fine on AS 2.X, but, I'm now developing with Kotlin so, I have to use AS 3.0.
I use AS 3.0 Canary 7 (This project is a fresh project)
This is my dummy class in my library (Stored in "domain".library.mylibrary)
class Test {
fun hello(): String {
return "hello"
}
}
And this is my (mylibrary) gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" //Declared in project level gradle: ext.kotlin_version = '1.1.3-2'
}
My gradlew.bat clean build --info log: https://pastebin.com/bfTZ5s4e
Android Studio does not generate a jar by default, but rather an AAR file. If you want to get a jar output, you need to implement apply plugin: 'maven-publish' on top of your mylibrary/gradle.build file and read the following document: Chapter 36. Maven Publishing (new)
Another note, is that I would suggest you not to use ProGuard directly on your release artifact, but rather provide a consumer ProGuard file and let the users of your library to handle that task, otherwise they will have a hard time referencing obfuscated code. Read my answer on this here
While the build task may generate an output, it is known that the assemble task (or assembleRelease) is the one that will generate your aar output.
Try running the following command:
./gradlew clean assembleRelease
and check the output in /mylibrary/build/outputs/apk/release/ if I am not mistaken.
i was working on a project, everything was fine but when i tried to run the app, i couldn't,i guess because i'm using a bundled version of google play services. so i i made sure that i update android studio and install the lastest google repository.
but it still wouldn't work. And when i click on install Repostiroy and sync project, still nothing happens.
please help me : this is my gradle ;
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.nefissa.pfe2"
minSdkVersion 16
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.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.google.android.gms:play-services:25.1.0'
testCompile 'junit:junit:4.12'
}
please where did i go wrong?
a screenshot;please what can i do? the click on install wouldn't work
replace it with compile 'com.google.android.gms:play-services:10.2.0'
and add apply plugin: 'com.google.gms.google-services' on the bottom of your gradle,
and make sure you added classpath 'com.google.gms:google-services:3.0.0'
in the Top-level build.gradle file
There might one of these problems can cause this issue, try any one of them.
Solution 1:
Try to updated the gradle plugin.
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
Then just Build->Clean project and everything works again.
Solution 2:
Go to the main module in your project, it's usually have the name app.
Then go to > Open Module Settings > in Properties change the Build Tools Version to 25.0.1
Then to make sure open the build.gradle file, and change compileSDKVersion & buildToolsVersion to 25 and 25.0.1 respectively.
If the above solution doesnt work.
Solution 3:
From this answer
"build cache" is enabled by default in build Android Plugin since 2.3.0. It creates files in build cache outside of project folder (e.g. in \Users\%username%.android\build-cache). Theese files are intended to be common between your projects.
And then Android Studio is unable to navigate in theese files.
You can disable Build Cache in gradle.properties file. just add android.enableBuildCache=false
In my Android studio I am only able to see the support libraries for the version 25.0.0 but my compile SDK version is 23 when I try to add com.android.support:recyclerview-v7:23.0.4 I get an error message that
Error:(27, 13) Failed to resolve: com.android.support:recyclerview-v7:23.0.4
but as per the SDK manager it shows that I have installed all the support libraries.
On top of that I am unable to locate the v7:23.0.4 libraries in the menu
File => Project Structure => Dependencies
Here are the screenshots
My Questions
Why am I unable to see the support libraries for the version v7:23.0.4 ?
If the support library is not installed how come it does not show in my SDK Manager ?
EDIT 1
Build.gradle(Module.app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "appnotic.quicknotes"
minSdkVersion 18
targetSdkVersion 23
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(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.2'
}
EDIT 2
1) it is not available from the repository, why? I don't know, but it is not the latest one for version 23, try com.android.support:recyclerview-v7:23.2.1 instead
2) you don't install the libraries with the SDK manager, that only install the source where gradle get the library from, the library itself gets downloaded when you build
I tried with 23.0.4 and could not get it, with 23.2.1 yes. If you can get version 25.0.0 it means that the repository is installed, maybe the gradle project is messed up somehow. Try to delete the project iml file and .idea folder and recreate it.