I'm trying to use the Parceler library in my Android Studio project.
The project has two modules, one is the app itself and the other is a personal android core library containing various helpers and generic entities.
However, I've added the Parceler dependency in my core library because I need it there too, so in the library build.gradle I've added the following lines:
compile "org.parceler:parceler-api:1.0.4"
apt "org.parceler:parceler:1.0.4"
I've not specified these lines inside the app build.gradle file because the dependency from Parceler will be imported automatically.
In my app I've defined an entity that have to be Parcelable and which implementation is:
#Parcel
public class Course {
public String name;
public Course() { /*Required empty bean constructor*/ }
public Course(String name) {
this.name = name;
}
}
But when I try to do
Course[] courses = ...retrieved from server...
Parcelable p = Parcels.wrap(courses);
The framework fires the following exception:
org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for [Lit.bmsoftware.lotoapp.network.entity.Course;, verify that your class is configured properly and that the Parcelable class [Lit.bmsoftware.lotoapp.network.entity.Course;$$Parcelable is generated by Parceler.
I've already read various posts for that exception but I can't find a solution for my problem.
Could anyone help me?
Thanks in advance :)
EDIT: build.gradle file
plugins {
id "me.tatarka.retrolambda" version "3.2.4"
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
retrolambda {
jvmArgs '-noverify' // Issues: using Google Play Services causes retrolambda to fail
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "it.bmsoftware.lotoapp"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
signingConfigs {
release {
storeFile file("*******.keystore")
storePassword "********"
keyAlias "*******"
keyPassword "*******"
}
}
buildTypes {
release {
//noinspection GroovyAssignabilityCheck
signingConfig signingConfigs.release
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
mavenLocal()
}
dataBinding {
enabled = true
}
// Fixes bug in Data Binding library (Source folders generated at incorrect location)
// applicationVariants.all { variant ->
// def variantName = variant.name.capitalize()
// def inputDir = "${buildDir}/intermediates/classes/${variant.dirName}"
// def sourceDir = "${buildDir}/generated/source/dataBinding/${variant.dirName}"
// def copyTask = tasks.create(name: "dataBindingFix${variantName}", type: Copy) {
// from inputDir
// into sourceDir
// include '**/*.java'
// }
// tasks["generate${variantName}Sources"].dependsOn copyTask
// variant.addJavaSourceFoldersToModel new File(sourceDir)
// }
return true
}
ext {
supportLibVersion = '23.1.1' // variable that can be referenced to keep support libs consistent
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':core')
compile "com.android.support:support-v13:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
//compile "com.android.support:percent:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile "org.parceler:parceler-api:1.0.4"
apt "org.parceler:parceler:1.0.4"
compile 'jp.wasabeef:recyclerview-animators:2.2.0'
}
The current release (1.0.4) does not support arrays of #Parcel annotated classes via the Parcels utility class. Instead, I'd suggest using a List:
List<Course> courses = ...retrieved from server...
Parcelable p = Parcels.wrap(courses);
Related
I'm trying to release APK in react native using ./gradlew bundleRelease I tried
Cleaning gradle
Adding multiDexEnabled true
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:transformDexArchiveWithDexMergerForRelease'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException:
com.android.builder.dexing.DexArchiveMergerException: Error while
merging dex archives: Program type already present:
org.apache.commons.io.Charsets Learn how to resolve the issue at
https://developer.android.com/studio/build/dependencies#duplicate_classes.
This is my build.gradle
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 23
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
googlePlayServicesVersion = "11+"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
}
}
app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js",
enableHermes: false
]
apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.package..."
minSdkVersion 23
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 33
versionName "33.0"
multiDexEnabled true
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
pickFirst '**/libjsc.so'
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libjsc.so'
pickFirst 'lib/arm64-v8a/libjsc.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
}
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.google.android.gms:play-services-gcm:17.0.0"
implementation "com.google.android.gms:play-services-location:17.0.0"
//Add these lines
implementation "com.google.android.gms:play-services-base:17.3.0"
//implementation "com.google.firebase:firebase-core:15.0.2"
implementation "com.google.firebase:firebase-messaging:20.2.1"
implementation "com.google.firebase:firebase-inappmessaging:19.0.7"
// implementation "com.google.firebase:firebase-inappmessaging-display:19.0.7"
//implementation 'com.android.support:multidex:1.0.3'
//implementation project(':#mauron85_react-native-background-geolocation')
addUnimodulesDependencies()
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/#react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'
Still failing but on my emulator and android device its working fine. Does anyone have this problem too? I really appreciate any idea thanks.
Hello Fellows when i was trying to add the admob SDK i got this error :
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: com.google.android.gms.security.ProviderInstaller
I've tried
Invalidating cache
cleaning and rebuilding
using ./gradlew build --stacktrace --info command
but without success.
This is what im getting every time :
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: com.google.android.gms.security.ProviderInstaller
Here are my app build.grable :
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "ar.rulosoft.mimanganu"
versionCode 92
versionName "1.92"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion 15
}
signingConfigs {
release {
storeFile file("../mimanganu.jks")
storePassword 'mimanganu'
keyAlias 'mimanganu'
keyPassword 'mimanganu'
}
debug {
storeFile file("../mimanganu.jks")
storePassword 'mimanganu'
keyAlias 'mimanganu'
keyPassword 'mimanganu'
}
}
buildTypes {
release {
lintOptions {
disable 'MissingTranslation'
disable 'NewApi' //Avoid problems in Android Studio 2.4 preview 6
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
debuggable true
signingConfig signingConfigs.debug
}
}
compileOptions.encoding = 'UTF-8'
flavorDimensions "builds"
productFlavors {
fdroid {
signingConfig signingConfigs.release
versionNameSuffix '-fdroid'
dimension "builds"
}
github {
signingConfig signingConfigs.release
//removed to maintain updates as now are
dimension "builds"
}
}
}
android.sourceSets {
test {
java.srcDirs += "$projectDir/src/testShare"
}
androidTest {
java.srcDirs += "$projectDir/src/testShare"
}
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:25.3.1'
}
dependencies {
final ANDROID_SUPPORT = '28.0.0'
implementation "com.android.support:support-v4:$ANDROID_SUPPORT"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.android.support:design:$ANDROID_SUPPORT"
implementation "com.android.support:appcompat-v7:$ANDROID_SUPPORT"
implementation "com.android.support:recyclerview-v7:$ANDROID_SUPPORT"
implementation "com.android.support:preference-v7:$ANDROID_SUPPORT"
api project(':imageviewtouchlibrary')
implementation 'rapid.decoder:library:0.3.0'
implementation 'rapid.decoder:jpeg-decoder:0.3.0'
implementation 'rapid.decoder:png-decoder:0.3.0'
implementation 'com.squareup.okhttp3:okhttp:3.11.0' //on 3.10.0 are deprecated some ciphers
implementation 'com.squareup.okio:okio:1.15.0'
implementation 'com.squareup.duktape:duktape-android:1.3.0'/* v 1.2.0 need 4+mb extra*/
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
implementation 'com.evernote:android-job:1.2.5'
githubImplementation 'com.google.android.gms:play-services-base:16.0.1'
// ADDED BY O D I N
implementation 'com.google.android.gms:play-services-ads:17.1.1'
// ADDED BY O D I N
implementation 'ch.acra:acra:4.9.2'
fdroidApi project(':fakegps')
// for device-based testing
androidTestImplementation "com.android.support:support-annotations:$ANDROID_SUPPORT"
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'junit:junit:4.12'
// for host-based testing
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.0-beta-1'
android {
testOptions {
unitTests {
includeAndroidResources = true
}
}
}
}
Project's build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
// ADDED BY O D I N
maven {
url "https://maven.google.com"
}
// ADDED BY O D I N
maven {
url 'https://github.com/suckgamony/RapidDecoder/raw/master/repository'
}
google()
}
}
after so many attempt to add the SDK i still can't find any solution for this, Hope i find it here
Add maven { url 'https://maven.fabric.io/public' } to your Project build.gradle. Like below. This fixed it for me.
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://maven.fabric.io/public' }
}
add
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Multidex support prior to Android 5.0
dependencies {
def multidex_version = "2.0.1"
implementation 'androidx.multidex:multidex:$multidex_version'
}
https://developer.android.com/studio/build/multidex
I've met the same kind of error : com.android.tools.r8.utils.AbortException: Error: Program type already present: [com.some.lib].
After dumping all the dependencies in console (via ./gradlew dependencies > ./dept.txt), I found out a new added aar does contain the same dependent library as reported above, so just exclude that out. It's done.
implementation ('the-new-library') {
transitive = true
exclude group : 'duplicate-lib-pkg', module:"duplicate-lib-name"
}
I am tring to add a C++ library into my Android project, but I keep getting the error:
Could not get unknown property 'jniLibs' for source set 'main' of type org.gradle.api.internal.tasks.DefaultSourceSet.
The project attempts to use a .so library of SQLite ( amalgamation).
How can I include the .so lib in my project and link it successfully to be able to call its functions?
Thank you all in advance.
My build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 15
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'
}
}
productFlavors {
}
buildToolsVersion '27.0.3'
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.+'
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'
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
remove config in build.gradle. This path is the default value of jniLibs, no customer config is needed.
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
or try with this config
sourceSets {
main {
jniLibs.srcDir(['src/main/jniLibs'])
}
}
copy the so file into app/src/main/jniLibs.
add the JNI java interface jar into your dependency.
System.LoadLibrary(libName) // for example you put xxx.so into jniLibs folder. here would be System.LoadLibrary("xxx")
Use the native method in JNI java class to call so method.
I am developing an application which enabling Multidex in order to avoid 65k limit. I want to add an external library in Jar type (i.e. iPay Jar SDK). I've Synchronized the Gradle and succeed but I failed to run the project.
The error message shown like below
Error:Execution failed for task ':app:shrinkDebugMultiDexComponents'.
java.io.IOException: Can't read [/[dir]/app/build/intermediates/multi-dex/debug/allclasses.jar] (Can't process class [com/ipay/IpayAcitivity.class] (Unknown verification type [14] in stack map frame))
This is my Gradle Code
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
mavenCentral()
mavenLocal()
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName '[My Package]'
}
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile fileTree(dir: 'libs', include: ['*.jar'])
//Libs folder contains: org.apache.http.legacy.jar
//and ipay88_androidv7.jar
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.github.rey5137:material:1.2.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "[My Application Id]"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'build/source/apt/debug']
resources.srcDirs = ['src/main/res']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
beta {
resources.srcDirs = ['app/src/beta/res']
res.srcDirs = ['app/src/beta/res']
}
}
signingConfigs {
release {
...
}
}
}
Before I added this type of external library (i.e. iPay Jar SDK), the application was running successfully. But the problem arised after I had added iPay Jar SDK (second Jar Library).
For further information, I had already followed this guide on https://developer.android.com/tools/building/multidex.html
But it didn't work my project.
What's your suggestion to fix this error ?
Try this:
public class MyApplication extends MultiDexApplication
{
#Override
protected void attachBaseContext(Context base)
{
super.attachBaseContext( base );
}
#Override
public void onCreate()
{
MultiDex.install(getTargetContext());
super.onCreate();
}
}
It seems your library is not compatible with Multidex. So you better update the library to the latest version(if an update is available). Or use only the required Google Play services API in your application and get rid off Multidex. Replace
compile 'com.google.android.gms:play-services:8.1.0' (the whole library)
this with something you use in your app like this
compile 'com.google.android.gms:play-services-ads:8.1.0' (library only for ads)
and remove this compile 'com.android.support:multidex:1.0.1'
You can find all the Google Play services API here https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project
beginner android developer so not a lot of experience on how the gradle works, I've tried looking at other examples but I still cant get my problem. Basically, I've just downloaded one of the sample projects from google android developer examples, and cant successfully build the project. I keep getting: Gradle sync failed: Gradle DSL method not found: 'compile()'
The app gradle is:
apply plugin: 'com.android.application'
android {
enforceUniquePackageName = false
compileSdkVersion android_compile_version
buildToolsVersion android_version
defaultConfig {
minSdkVersion android_min_sdk_version
targetSdkVersion android_compile_version
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile "com.android.support:appcompat-v7:${appcompat_library_version}"
compile "com.android.support:support-v4:${support_library_version}"
compile project(':libraries:BaseGameUtils')
compile 'com.google.android.gms:play-services:4.3.23'
}
buildscript {
repositories {
jcenter()
}
}
and as for the project gradle:
// this is the parent build configuration for all the sample projects.
// for more information on gradle build files when used in a multi-project build, see
// http://gradle.org/docs/current/userguide/multi_project_builds.html
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
// allprojects apply to every project
allprojects {
repositories {
jcenter()
}
ext {
android_compile_version = 23
android_version = '23.0.1'
android_min_sdk_version = 9
appcompat_library_version = '23.0.1'
support_library_version = '23.0.1'
gms_library_version = '8.1.0'
}
}