I have experience with Android development on Eclipse, but I'm quite new to this gradle stuff.
I created a project on Android Studio and tried adding native library support. I followed the documents on android.com
Android NDK Preview
Experimental Plugin User Guide
I bumped into the following problem and I'm not even familiar with the terminology! It says: Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'
Suggestions did not solve the problem. How can I solve it?
Here are the contents of the build.gradle and app/build.gradle:
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}
app/build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.0"
defaultConfig.with {
applicationId = "com.example.wofm"
minSdkVersion = 15
targetSdkVersion = 23
versionCode = 1
versionName = "1.0"
}
}
android.ndk {
moduleName = "wofmUtil"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles = getDefaultProguardFile('proguard-android.txt')
proguardFiles += 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
}
You should use minSdkVersion.apiLevel and targetSdkVersion.apiLevel instead of minSdkVersion and targetSdkVersion. And I also had a problem with getDefaultProguardFile() so I had to remove it.
Related
I am looking for a good way to import Room Persistence inside of my Lib to export .aar . I have the following issue that .aar cannot handle dependencies.
When I export my arr and import into another project as lib, it seems as it has no scope to room.
my lib Gradle file :
apply plugin: 'com.android.library'
apply plugin: 'maven'
archivesBaseName = '*****'
android {
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 5
versionName "1.1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Write out the current schema of Room
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
configurations {
deployerJars
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'android.arch.persistence.room:runtime:1.1.0-beta3'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.0-beta3'
}
Thanks.
I have project and I added another project as module and I have big problem with this error message:
Error:Execution failed for task
':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge
dex
I tried many solutions in stackoverflow and google but i don't found an answer.
For example:
I try added to defaultConfig multiDexEnabled true.
I try to clean and rebuild.
I try to Invalidate catch/Restart and then rebuild.
My project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "adms.foxitpdf"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation files('libs/FoxitRDK.jar')
compile project(path: ':uiextensions_src')
}
And my module gradle:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions{
abortOnError false
}
}
dependencies {
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
implementation files('src/libs/FoxitRDK.jar')
}
task clearAar(type: Delete){
delete '../FoxitRDKUIExtensions.aar'
}
task makeAar(type: Exec){
dependsOn(clearAar,build)
def fromFile = 'build/outputs/aar/'
def intoFile = '../'
if(org.gradle.internal.os.OperatingSystem.current().windows) {
commandLine "cmd",
'-/C', 'copy', file("$fromFile/uiextensions_src-release.aar").absolutePath, file("$intoFile/FoxitRDKUIExtensions.aar")
}else {
commandLine "cp",
file("$fromFile/uiextensions_src-release.aar").absolutePath, file("$intoFile/FoxitRDKUIExtensions.aar")
}
}
makeAar {}.dependsOn(clearAar,build)
task makeJavaDoc(type: Javadoc) {
List<String> mSourcePath = new ArrayList<String>();
mSourcePath.add("../../fsdk/app/src/main/java/com/foxit/sdk/");
mSourcePath.add("src/main/java/com/foxit/uiextensions/UIExtensionsManager.java");
mSourcePath.add("src/main/java/com/foxit/uiextensions/Module.java");
mSourcePath.add("src/main/java/com/foxit/uiextensions/pdfreader/impl/PDFReader.java");
mSourcePath.add("src/main/java/com/foxit/uiextensions/controls/menu/IMenuView.java");
mSourcePath.add("src/main/java/com/foxit/uiextensions/controls/menu/MoreMenuConfig.java");
mSourcePath.add("src/main/java/com/foxit/uiextensions/controls/menu/MoreMenuModule.java");
mSourcePath.add("src/main/java/com/foxit/uiextensions/controls/toolbar/IBaseItem.java");
mSourcePath.add("src/main/java/com/foxit/uiextensions/controls/toolbar/IBarsHandler.java");
mSourcePath.add("src/main/java/com/foxit/uiextensions/controls/propertybar/IMultiLineBar.java");
source = mSourcePath;
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
Properties properties = new Properties()
InputStream inputStream = project.rootProject.file('local.properties').newDataInputStream() ;
properties.load( inputStream )
//读取文件
def sdkDir = properties.getProperty('sdk.dir')
ext.androidJar = sdkDir + "/extras/android/support/annotations/android-support-annotations.jar"
classpath += project.files(ext.androidJar)
destinationDir = file("../../docs/api_reference_android")
failOnError false
}
makeJavaDoc {
options {
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PUBLIC
locale = "en"
title = "Document of RDK for Android"
// fsdk overview
Map<String,List<String>> map = new HashMap<>();
List<String> fsdkOverViews= new ArrayList<>();
fsdkOverViews.add("com.foxit.sdk");
fsdkOverViews.add("com.foxit.sdk.*");
map.put("Fsdk Packages",fsdkOverViews);
// UIExtensions overview
List<String> uiExtendOverViews = new ArrayList<>();
uiExtendOverViews.add("com.foxit.uiextensions");
uiExtendOverViews.add("com.foxit.uiextensions.*");
map.put("UIExtenstions Packages",uiExtendOverViews);
groups = map;
}
}
I use with Android Studio to 3.0
Someone have idea why?
I guess you need to include this below one to your gradle as well as add dependencies and include in manifest also. If you have enabled only in gradle and does not include in manifest and dependencies then give it a shot.
multiDexEnabled true
add to your dependencies
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
gradle file
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "adms.foxitpdf"
minSdkVersion 15
targetSdkVersion 24
versionCode 9
versionName "1.0"
multiDexEnabled true //Add this
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
Depending on how you override Application add this to your manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
or we can just do like this and again include in manifest with name tag.
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Read full story here
I am starting new android project from android studio. Below is the login screen i see . I don't know what i am missing out here.
I have no idea why is the accentColor is being shown something like this?
build.gradle ( module level )
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
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:' + rootProject.ext.junitVersion
compile 'com.loopj.android:android-async-http:' + rootProject.ext.loopjHttpAsyncTask
compile 'com.roughike:bottom-bar:' + rootProject.ext.bottomBar
compile 'com.android.support:appcompat-v7:' + rootProject.ext.supportLibraryVersion
compile 'com.android.support:design:' + rootProject.ext.supportLibraryVersion
}
build.gradle (project level)
// 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.2.0-alpha3'
// 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
}
ext {
//app related
compileSdkVersion = 23
buildToolsVersion = "23.0.3"
minSdkVersion = 16
targetSdkVersion = 23
//android related library
constraintLayout = "1.0.0-alpha3"
junitVersion = "4.12"
supportLibraryVersion = "23.3.0"
//custom libraries
bottomBar = "1.3.9"
loopjHttpAsyncTask = "1.4.9"
}
The issue caused by gradle build-tool version. Changing build tool version to stable one would solve it
replace
classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
with
classpath 'com.android.tools.build:gradle:2.1.0'
my module build.gradle
apply plugin: 'com.android.application'
model {
android {
// 编译SDK的版本
compileSdkVersion = 23
// build tools的版本
buildToolsVersion = "23.0.3"
//useLibrary = 'org.apache.http.legacy'
defaultConfig.with {
// 应用的包名
applicationId = "com.example.administrator.design"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
tasks.withType(JavaCompile) {
//指定编译JDK版本
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
}
android.ndk {
moduleName = "test"
ldLibs += "log"
abiFilters += "armeabi"
abiFilters += "armeabi-v7a"
abiFilters += "x86"
}
android.productFlavors {
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
}
android.buildTypes {
release {
// 是否进行混淆
minifyEnabled = false
// 混淆文件的位置
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles += file('proguard-android.txt')
proguardFiles += file('proguard-rules.pro')
//resValue "string", "facebook_app_id", '"597651723652854"'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//testCompile 'junit:junit:4.12'
compile 'org.xutils:xutils:3.3.20'
...
}
my project build.gradle
buildscript {
repositories {
jcenter()
//mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle wrapper
#Mon Mar 28 16:31:26 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
if I use "com.android.tools.build:gradle:0.20" in project build.gradle, and make some according changes it just works fine, But I want the new feature instant, run I have googled almost one afternoon.
Looks like you used an experimental gradle plugin version. The stable version 2.0.0 and the experimental version have some differences regarding the notation in the build.gradle file.
For example the android block needs to be outside the model block. And some attribute specifications are slightly different. Have a look at the Experimental Gradle Plugin User Guide, especially the red highlighted parts in the build.gradle example file.
Also I'm not really sure, but the non-experimental version still doesn't have full NDK support. Although it looks like the experimental version 0.6 does support the NDK as well as Instant Run, so you might use the version 0.6 instead of 2.0.
Could not find property jni and source set 'main'
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "22.0.1"
defaultConfig.with {
applicationId = "com.example.native_activity"
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 9
}
sourceSets.main {
jni.srcDirs = [] // This prevents the auto generation of Android.mk
jniLibs.srcDir = 'src/main/libs'
// This is not necessary unless you have precompiled libraries in your project.
}
}
Here is the stacktrace:
Caused by: org.gradle.model.internal.core.ModelRuleExecutionException: Exception thrown while executing model rule: model.android
at org.gradle.model.internal.registry.DefaultModelRegistry.fireMutation(DefaultModelRegistry.java:485)
at org.gradle.model.internal.registry.DefaultModelRegistry.access$1500(DefaultModelRegistry.java:45)
at org.gradle.model.internal.registry.DefaultModelRegistry$RunModelAction.apply(DefaultModelRegistry.java:1464)
at org.gradle.model.internal.registry.DefaultModelRegistry.transitionTo(DefaultModelRegistry.java:341)
at org.gradle.model.internal.registry.DefaultModelRegistry.transition(DefaultModelRegistry.java:419)
at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrMaybeLater(DefaultModelRegistry.java:183)
at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrLater(DefaultModelRegistry.java:175)
at org.gradle.execution.TaskNameResolver.selfClose(TaskNameResolver.java:101)
at org.gradle.execution.TaskNameResolver.selfClosedTasksNode(TaskNameResolver.java:114)
... 60 more
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method main() for arguments [build_f1cmjkxjjzysskbrs6852ixyj$_run_closure1_closure2_closure7#8c09fa7] on SourceSet container.
I googled like mad for the last 2 hours...
As Awanish said - read the Experimental Plugin User Guide step by step VERY carefully. For even more clearance check the build.gradle files in the ndk-samples provided by google.
sourceSets.main { } has different syntax and should be outside the android { } block. In your case it should look something like this:
model {
android {
//...
}
android.sources {
main {
jniLibs {
source {
srcDirs 'libs'
}
}
}
}
}
In my case it was an exact opposite to tochkov answer:
This syntax - with the jniLibs outside android block - gave me an error:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.myproject"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
and this syntax - inside android block - fixed it:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.myproject"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
}
It seems like you are trying to use the grade experimental plugin!
Make sure you have grade-2.5 in your gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
and this in your project's build.gradle dependencies tag
classpath 'com.android.tools.build:gradle-experimental:0.1.0'
Instead of guessing a lot of things, let me redirect you to the user guide, where the documentation explains migration from the standard to experimental plugin in detail. Take a look here!
Try these fixes. Post more details if these don't work for you, I will try to help. :)
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.jeremy.test"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles.add(file('proguard-android.txt'))
}
}
ndk {
moduleName "hello-android-jni"
}
}
android.sources.main {
java.source.srcDirs = ["src/main/java", "/Users/jeremy/Repositories/hello/src/android/java"]
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
The above is copied from my experimental ndk project, this works for me.
See the android.sources.main section.