Bootstrapping Alibaba Cloud Message Service in Android Application? - alibaba-cloud

I want to use the Alibaba Cloud message service within my Android Application. But I see there no Android SDK available. I am trying to use JAVA SDK as an Alternative, there is no luck.
Is this the correct way of using the service or do I have to use the API interface as the final resort?

Yes, In this case, you can use JAVA SDK. JAVA SDK's are compatible with Android, Keep in mind that you might need to resolve the dependencies as mentioned.
Download the aliyun-sdk-mns-1.1.8.jar & jaxb-api-2.2.12.jar and place it under app > libs
And update the gradle with the following lines
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
useLibrary 'org.apache.http.legacy'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:multidex:1.0.2'
implementation files('libs/aliyun-sdk-mns-1.1.8.jar')
implementation files('libs/jaxb-api-2.2.12.jar')
}
The above should fix all the issues.

Related

How Springboot lock the libs' version, like Rails's Gemfile.lock?

I understand there is library dependency management in Springboot so that the correct version of starter kits will be picked for the Springboot version. However I do not fully understand how the third-party libs' versions are controlled.
For example, in build.gradle file, we can use a lib like this:
implementation('org.liquibase:liquibase-core') .
I know that Gradle's logic is to pick the latest version if no version is specified. I am not sure if there are any tools like a lock file to lock down ALL the versions used by this application, or we have to specify the version like:
compileOnly 'org.projectlombok:lombok:1.18.4' ?
So that we can be confident that all the libs used in the team are identical.
The best practice recommended by gradle is to declare dependencies without versions and use dependency constraints.
dependencies {
implementation 'org.liquibase:liquibase-core'
}
dependencies {
constraints {
implementation 'org.liquibase:liquibase-core:3.6.2'
}
}

Supporting multiple gradle versions in single build.gradle

Due to build tools, my gradle file has to be compatible both with Android Gradle 2.1.3 and the latest Android Gradle version. As the latest Android Gradle Plugin has introduced the new implementation and api configuration, and is planning to remove the compile configuration, I am trying to figure out a way to write script that it should bebe able to support both versions.
The idea would be to use something like
def _api = api
and in the dependencies use _api instead of api.
Later we plan to add add some code like;
if (oldVersion)
_api = compile
I have tried this code as is, but it is invalid code.
Any ideas how it should be coded?
Thanks in advance
The notation:
dependencies {
api "org.example:example:1.0"
}
is really syntactic sugar for
dependencies {
add("api", "org.example:example:1.0")
}
so you could solve that problem by defining String variables, whose value depends on the Gradle version.

Android Gradle plugin API for development

Recently I started learning about custom Gradle plugins. I am ok with it. Now I want to customize the Android build with my own plugin.
Below are my requirements:
I want to add product flavors dynamically to my Android app from my custom plugin
I want to configure the build tools version and other sdk versions from my custom plugin.
Is there an API google has released for this?
I have gone through the below Android DSL reference.
http://google.github.io/android-gradle-dsl/
What is the dependency I need to add to my custom plugin to use the above Android Gradle dsl APIs?
You can add a dependency to the Android gradle plugin itself:
classpath 'com.android.tools.build:gradle:3.0.1'
This will put the plugin in your classpath so you can reuse all the classes you want. There's no real documentation but you can always read the source code.

Kotlin Modules with Gradle Multi-Project

Kotlin got rid of package level visibility for module level visibility. I think that was a great idea, except it's difficult to get multiple Kotlin modules working in a Gradle multi-project setup.
I'm using Gradle Wrapper 3.1, with Android Studio 2.2 and Kotlin 1.0.4
Here is my structure:
Project
----myapp (android application)
----lib (android library)
----commons (android library)
// myapp/build.gradle
dependencies {
compile project(':lib')
}
// lib/build.gradle
dependencies {
compile project(':commons')
}
When I try to sync or build I get the following error:
Error:A problem occurred configuring project ':lib'.
Cannot change dependencies of configuration ':lib:default' after it has been included in dependency resolution.
The only thing that has worked is to make sure that the module names have a lexical order that matches the order they need to be built in, which is ridiculous, and not a proper solution.
I know I can publish lib and commons as artifacts, but I'd really prefer to not do that.
Anyone have any suggestions?

Android Studio doesn't recognize Espresso classes

I'm running Android Studio 0.5.0 with Gradle 1.11. I'm trying to install Espresso library from com.jakewharton.espresso:espresso:1.1-r2. For some reason AS couldn't recognize Espresso classes after project synchronization. So every time I try to import import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; inside androidTest folder files it marks it as invalid.
Here's my build.gradle:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.squareup.dagger:dagger-compiler:1.2.1'
compile 'com.squareup.dagger:dagger:1.2.1'
androidTestCompile ('com.jakewharton.espresso:espresso:1.1-r2') {
exclude group: 'com.squareup.dagger'
}
}
External libraries:
So this is basically a bug with Android Studio (i'm guessing).
Reference:
Issue raised in adt-dev groups
Actual bug - #66841
Workaround (until the bug is fixed):
Add a duplicate provided dependency in your gradle file like so:
dependencies {
// ...
provided 'com.jakewharton.espresso:espresso:1.1-r2'
androidTestCompile ('com.jakewharton.espresso:espresso:1.1-r2') {
exclude group: 'com.squareup.dagger'
}
}
This issue was driving me crazy. And seems like it's a known bug in Android Studio. In my case it resolved after I've changed Build Type from Release to Debug for the parent app. Hope this may be helpful for someone
Espresso 2.0
Recently Espresso 2.0 was released making it now part of the Android Support Library. This was announced on the android dev blog.
Setup Guide
With that they also linked an updated setup guide. There you can find instructions to configure from scratch or to update your existing espresso config for 2.0.
Other Tips
Changes are the above 2 links contain all information you need. If not I have listed some common mistakes below
Upgrade Android Studio to 1.0.*
Start by upgrading your android Studio build. You should be able to get at least 1.0 from the stable builds channels (=default). So just use the menu option Android Studio > Check for updates... .
To get the latest from the latest you can also go into Preferences, search for updates and change the channel to canary channel.
Update Android Support Library to v 11+
Espresso was included in the Support library from version 11 so you have to get at least that version. Check for updates using the Android SDK manager. The Support Library is within the Extras tree at the bottom.
New dependencies and namespace
If upgading from an older espresso release you'll have to update the dependencies and the namespace. For new projects just add these to the dependencies in your build.gradle file.
dependencies {
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}
And since the namespace changed you'll have to update all imports:
android.support.test.espresso
Note that it's easier to use static imports. Some commonly used imports as an example:
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
For asserts use hamcrest, again some examples:
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace;
Instrumentation runner
The test runner needs to be configured in both your build.gradle file within defaultConfig and the run configuration used to launch your tests from Android Studio.
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
And in your run configuration use this as instrumentation runner (full class name only):
android.support.test.runner.AndroidJUnitRunner
Example test case
And an example test case to finish with. Note that MainActivity is your actvitiy you want to test. The tests themselves are public methods that start with test, like testListGoesOverTheFold in the below example.
#LargeTest
public class HelloWorldEspressoTest extends ActivityInstrumentationTestCase2<MainActivity> {
public HelloWorldEspressoTest() {
super(MainActivity.class);
}
#Override
public void setUp() throws Exception {
super.setUp();
getActivity();
}
public void testListGoesOverTheFold() {
onView(withText("Hello world")).check(isDisplayed());
}
}
For more information on writing tests visit the espresso start guide.
Six months later this is still an issue and the bug referenced by the original responder has been reopened: https://code.google.com/p/android/issues/detail?id=66841 and given higher priority. I have not yet been able to get Android Studio to recognize Espresso classes and using the "provided" scope for dependencies didn't work to fix the issue for me. (Using AS 0.8.6 and Gradle 0.12.2)
according to http://tools.android.com/tech-docs/new-build-system/user-guide
only one build type is tested, by default it is debug Build Type.
So check that you are using debug build variant and rebuild the application. On other build types all your androidTest dependencies will not be visible.
If you need to test your current build type you can do something like this:
android {
...
testBuildType "staging"
}
Android Studio 1.5.1 didn't realize onView() or onData() methods in my case. I just did a static import of the Espresso class and all it's methods.
I added the below line and everything worked perfectly.
import static android.support.test.espresso.Espresso.*;
You're not specific about what source file you're seeing the error in, but based on my testing, I think you're trying to access the Espresso classes from one of your main application classes (inside src/main/java/). If so, that won't work, because you've included Espresso via an androidTestCompile dependency include, which makes it accessible only to your test classes, which must be under src/androidTest/java.
I've tried every solution what guys guessed above and still got the class not found error.
I figured out my solution, it saved my day.
So if you open the project tab on left to your project folders in Studio and check the build variants you can see that, your project is set to unit test. You have to re-set it to Android Instrumentation Tests and make sure your test.java file is under
**src\androidTest\java**
try these dependencies:
implementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
I was having this issue and I went through and added every espresso library I could add to my gradle file. Wait for the yellow lightbulb to come on and then click add library and search for the espresso libraries you don't have. I don't know if this will work for everyone but it worked for me.

Resources