Android Studio generated signed apk issue Gradle - android

I'm trying to export a signed apk of my exported project from eclispe ADT to Android Studio.
I have 2 issues:
Error:(16, 0) Gradle DSL method not found:
'lintOptions()'
Possible causes:The project 'gigCheck2' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
And when I'm trying to generate the apk:
Missing Gradle Project Information. Please check if the IDE
successfully synchronized its state with the Gradle Project
Model.
I've two build.gradle
1-Inside root project:
<code>// 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.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}</code>
2-In the app
<code>
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.project.client.android"
minSdkVersion 7
targetSdkVersion 10
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
sourceSets {
main {
manifest.srcFile 'app/src/main/AndroidManifest.xml'
}
}
}
dependencies {
compile files('lib/commons-codec-1.7.jar')
compile files('lib/commons-io-2.4.jar')
compile files('lib/commons-lang-2.6.jar')
compile files('lib/core.jar')
compile files('lib/javase.jar')
compile files('lib/ksoap2-android-assembly-3.0.0.jar')
}
</code>

Remove lintOptions in root level gradle file and add it in app level gradle file.
Your app>build.gradle look like this.
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.project.client.android"
minSdkVersion 7
targetSdkVersion 10
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
sourceSets {
main {
manifest.srcFile 'app/src/main/AndroidManifest.xml'
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {
compile files('lib/commons-codec-1.7.jar')
compile files('lib/commons-io-2.4.jar')
compile files('lib/commons-lang-2.6.jar')
compile files('lib/core.jar')
compile files('lib/javase.jar')
compile files('lib/ksoap2-android-assembly-3.0.0.jar')
}

lint options should be included in your module gradle not project:
android{
defaultConfig {
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
}

Related

How to fix NDK build error in AndroidStudio

I want build my project from AndroidStudio into my phone, but when run button in Android Studio. show me this error :
Error:Execution failed for task ':app:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
Build.Gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.companyname.gamename"
minSdkVersion 14
targetSdkVersion 23
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
How can i fix it?
paste below code in your build.gradle(Module:app)
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes{
}
Paste this in build.gradle above buildTypes{}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes{
}

Android project there is no output dir after gradle build success?

I am learning Gradle for Android recently. For learning impressively, i create all android application files manually.
my project dirs as below
package name : com.wonbin.gradledemo
project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
app module build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.wonbin.gradledemo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "adroid.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
lintOptions {
htmlReport true
htmlOutput file("lint-results.html")
}
}
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:23.4.0'
testCompile 'junit:junit:4.12'
}
./gradlew build is successful and there are 'intermediates' and 'generated'
dirs , but no outputs dir, i don't know what to do!
Thanks a lot!
You need not only to build, but to assemble it as well.
To do this you can run a gradle task
assembleDebug
Or use Build -> Build APK main menu item

Gradle aar library dependecy in module: failed to resolve

I'm a newbie with gradle and I'm having a dependecy problem. I have the follow project structure:
-MyApp
-MyAppLibrary
-MyAppPro
-MyAppFree
-ThirdPartyLibraryWrapper
--libs\ThirdPartyLibrary.aar
Both MyAppPro and MyAppFree depend on MyAppLibrary, which depends on ThirdPartyLibraryWrapper. As the name suggests, ThirdPartyLibraryWrapper is a wrapper on an external library, namely ThirdPartyLibrary.aar.
This is my configuration:
build.gradle MyAppPro
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':MyAppLibrary')
}
build.gradle MyAppLibrary
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':ThirdPartyLibraryWrapper')
compile 'com.squareup.picasso:picasso:2.5.2'
}
build.gradle ThirdPartyLibraryWrapper
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ThirdPartyLibrary-0.1.0', ext: 'aar')
compile "com.android.support:support-v4:22.0.0"
compile fileTree(dir: 'libs', include: 'volley.jar')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
}
When gradle sync completes, I have got this error:
MyApp/MyAppFre/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppLibrary/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppPro/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
Can someone help me figure out where is the issue?
The other projects are seeing that the :ThirdPartyLibraryWrapper project depends on an artifact called ThirdPartyLibrary-0.1.0:aar. Java (and Android) libraries do not bundle their own dependencies together - instead, they simply publish a list of their dependencies. The consuming project is then responsible for loading not only the library it directly depends on, but all of the libraries that library depends on.
The net effect of this is that :MyAppFree is loading in :ThirdPartyLibraryWrapper, then seeing that :ThirdPartyLibraryWrapper depends on ThirdPartyLibrary-0.1.0:aar and so thus trying to load that in as well. However, :MyAppFree doesn't know where ThirdPartyLibrary-0.1.0:aar lives.. and so it fails.
The solution will be to place similar repositories blocks in all your other projects. Try this:
repositories {
flatDir {
dirs project(':ThirdPartyLibraryWrapper').file('libs')
}
}
Using the project(...).file(...) method will free you from having to hardcode paths, and will instead use the Gradle DSL to resolve the filesystem path by looking up the project and having it do the resolution dynamically.

Gradle can't find library

I am trying to include Otto library in my project, but am getting this error:
> Could not resolve all dependencies for configuration ':maptest:_debugCompile'.
> Could not find com.squareup:otto:1.3.4.
I have tried cleaning project, running Tools -> android -> sync project with gradle files but that gives me the same error.
My build.gradle is the following:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.squareup:otto:1.3.4'
}
You should add maven central repository, so gradle know where so search for library.
repositories {
mavenCentral()
}
Did you import Otto library into Android Private Libraries? Try clean project this way: Project -> Clean...
You may check this out.

How to make runProguard work for the android-library Gradle plugin?

I would like to run ProGuard on release build of my Android library. Below is my build.gradle file that is within my project.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/../lib'
}
}
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
}
Running gradlew clean or gradlew build returns the following error:
> Could not find method buildTypes() for arguments [build_25r1m0a3etn5cudtt5odlegprd$_run_closure2_closure10#5f3306ad] on project
It seems that plugin android-library is missing the buildTypes method. If I change apply plugin to android, gradlew runs successfully. However, this is a library project and I would like to keep it so. Other parts my my gradle.build (not mentioned here) rely on the project being a library.
Is there any way to make the android-library plugin run ProGuard on build?
Solved my issue by taking release out of buildTypes like so:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/../lib'
}
}
}
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile 'proguard-android.txt'
}
}
Also note that I added another proguardFile under release. This fixed another issue I was having after solving the initial buildTypes problem.

Categories

Resources