Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for android 12 devices #481

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@

buildscript {
repositories {
jcenter()
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:4.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

ext{

compileSdkVersion = 24
buildToolsVersion = '23.0.3'
compileSdkVersion = 32


group = 'org.eclipse.paho'

sampleArchivesBaseName = 'org.eclipse.paho.android.sample'
sampleVersion = '1.1.1'
sampleArchivesBaseName = 'inder.paho.mqtt'
sampleVersion = '1.1.3'

serviceArchivesBaseName = 'org.eclipse.paho.android.service'
serviceVersion = '1.1.1'
serviceArchivesBaseName = 'inder.paho.mqtt'
serviceVersion = '1.1.4'

clientVersion = '1.1.0'

mavenUrl = "https://repo.eclipse.org/content/repositories/paho-releases/"

supportLibVersion = '24.2.1'
supportLibVersion = '27.0.2'

}

Expand All @@ -57,6 +57,8 @@ println "SDK dir: $sdkDir"
allprojects {

repositories {
google()
mavenCentral()
jcenter()
maven {
url "file://$sdkDir/extras/android/m2repository/"
Expand Down
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Tue Jan 24 11:18:55 GMT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
4 changes: 4 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jdk:
- openjdk11
before_install:
- ./scripts/prepareJitpackEnvironment.sh
22 changes: 11 additions & 11 deletions org.eclipse.paho.android.sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
// buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId rootProject.ext.sampleArchivesBaseName
minSdkVersion 16
targetSdkVersion 24
targetSdkVersion 32
versionCode 1
versionName "0.1"
}
Expand All @@ -32,13 +32,13 @@ repositories {


dependencies {
//compile fileTree(dir: '../org.eclipse.paho.android/service/libs', excludes: ["org.eclipse.paho.client.mqttv3-${rootProject.ext.clientVersion}.jar"], include: '')
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
compile "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
compile "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}"
compile (project(':org.eclipse.paho.android.service')){
//exclude module: "org.eclipse.paho.client.mqttv3"
transitive=true
implementation fileTree(dir: '../org.eclipse.paho.android/service/libs', include: '')
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}"
implementation(project(':org.eclipse.paho.android.service')){
// exclude module: "org.eclipse.paho.client.mqttv3"
//transitive=true
}
}

Expand All @@ -48,7 +48,7 @@ task publishAPK(type: Copy) {
}


configurations.compile.exclude module: 'org.eclipse.paho.client.mqttv3'
task debug << {
//configurations.compile.exclude module: 'org.eclipse.paho.client.mqttv3'
task debug doLast {
configurations.compile.each { println it}
}
3 changes: 2 additions & 1 deletion org.eclipse.paho.android.sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

<activity
android:name=".activity.MainActivity"
android:label="@string/app_name" >
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
71 changes: 37 additions & 34 deletions org.eclipse.paho.android.service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'maven-publish'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
// buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion 9
targetSdkVersion 24
targetSdkVersion 32

testApplicationId "org.eclipse.paho.android.service.test"
}
Expand Down Expand Up @@ -36,19 +36,21 @@ configurations {
}

dependencies {
compile "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}"
compile "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
compile fileTree(include: ['*.jar'], dir: 'libs')
api "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}"
api "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
api fileTree(include: ['*.jar'], dir: 'libs')
}

android.libraryVariants.all { variant ->
task("generate${variant.name}Javadoc", type: Javadoc) {
doFirst {
ext.androidJar =
"${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
}

title = "$name $version API"
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar =
"${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.links("http://d.android.com/reference/");
exclude '**/BuildConfig.java'
Expand Down Expand Up @@ -92,41 +94,42 @@ task("generateJavaDocJar", type: Jar, dependsOn: (rootProject.ext.serviceVersion
publishing {
publications {
paho(MavenPublication) {
groupId 'org.eclipse.paho'
artifact generateSourcesJar
artifact generateLibraryJar
artifact generateJavaDocJar
groupId 'inderrapido'
artifact "$buildDir/outputs/aar/" + rootProject.ext.serviceArchivesBaseName + "-" + rootProject.ext.serviceVersion + ".aar"
}
}
repositories {
if (project.hasProperty('eclipseRepoUsername')) {
maven {
name 'eclipse'
url 'https://repo.eclipse.org/content/repositories/paho-' + (rootProject.ext.serviceVersion.endsWith('-SNAPSHOT') ? 'snapshots/' : 'releases/')
credentials {
username eclipseRepoUsername
password eclipseRepoPassword
}
}
} else {
maven {
url "$buildDir/repo"
}
}
}
// repositories {
// if (project.hasProperty('eclipseRepoUsername')) {
// maven {
// name 'eclipse'
// url 'https://repo.eclipse.org/content/repositories/paho-' + (rootProject.ext.serviceVersion.endsWith('-SNAPSHOT') ? 'snapshots/' : 'releases/')
// credentials {
// username eclipseRepoUsername
// password eclipseRepoPassword
// }
// }
// } else {
// maven {
// url "$buildDir/repo"
// }
// }
// }
}


task debug << {
task debug doLast {
configurations.compile.each { println it}
}
// Required to bundle Java library Jar in AAR
clean.doLast{
copyLibs.execute()
clean.dependsOn("copyLibs").doLast{
//copyLibs.execute()
// println "Copying MQTT Jar into libs directory"
// from configurations.compile
// into 'libs'
// include 'org.eclipse.paho*'
}
assemble.doLast {
renameReleaseAAR.execute()
assemble.dependsOn("renameReleaseAAR").doLast {
// renameReleaseAAR.execute()
}

clean.doFirst {
Expand Down
5 changes: 3 additions & 2 deletions org.eclipse.paho.android.service/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<manifest
package="org.eclipse.paho.android.service">
<manifest package="org.eclipse.paho.android.service"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<application>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service;

import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttPingSender;
import org.eclipse.paho.client.mqttv3.internal.ClientComms;

import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
Expand All @@ -30,6 +25,11 @@
import android.os.PowerManager.WakeLock;
import android.util.Log;

import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttPingSender;
import org.eclipse.paho.client.mqttv3.internal.ClientComms;

/**
* Default ping sender implementation on Android. It is based on AlarmManager.
*
Expand Down Expand Up @@ -60,6 +60,16 @@ public AlarmPingSender(MqttService service) {
that = this;
}


private int pendingIntentFlags() {
if (Build.VERSION.SDK_INT >= 23) {
return PendingIntent.FLAG_IMMUTABLE;
} else {
return PendingIntent.FLAG_UPDATE_CURRENT;
}
}


@Override
public void init(ClientComms comms) {
this.comms = comms;
Expand All @@ -74,7 +84,7 @@ public void start() {
service.registerReceiver(alarmReceiver, new IntentFilter(action));

pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent(
action), PendingIntent.FLAG_UPDATE_CURRENT);
action), pendingIntentFlags());

schedule(comms.getKeepAlive());
hasStarted = true;
Expand All @@ -95,7 +105,7 @@ public void stop() {
try{
service.unregisterReceiver(alarmReceiver);
}catch(IllegalArgumentException e){
//Ignore unregister errors.
//Ignore unregister errors.
}
}
}
Expand Down
Loading