I'm having trouble referencing a groovy class i've created. Here are the steps:
my build.gradle file has all required dependencies:
apply plugin: 'com.android.application'
apply plugin: 'groovyx.grooid.groovy-android'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
packagingOptions {
// workaround for http://stackoverflow.com/questions/20673625/android-gradle-plugin-0-7-0-duplicate-files-during-packaging-of-apk
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/groovy-release-info.properties'
}
defaultConfig {
applicationId "com.example.uen.myrxjavaandroidproject"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.netflix.rxjava:rxjava-android:0.20.7'
compile 'com.squareup:otto:1.3.5'
compile 'org.codehaus.groovy:groovy:2.4.3:grooid'
}
And gradle is synched successfully.
then i created a folder under main called 'groovy' such that my project structure looks like the following:
notice i have a groovy class called "Hello", it looks like this:
public class Hello {
String name;
public void sayHello() {
System.out.println("Hello "+getName()+"!");
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
now in my MainActivity.java class i try to instantiate Hello class but its not being recognized. I am doing this:
Hello myHello = new Hello();
what am i doing wrong ?
If you want to use a Groovy class from your Java sources, then your Java file must be found in the "groovy" directory. It's done this way to enforce joint compilation (Java classes consuming Groovy classes or the other way).
And independently of this, for the sake of Grooviness, your Hello Groovy class can be reduced to:
class Hello {
String name
void sayHello() {
println "Hello $name!"
}
}
Related
I have looked at this article
[INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
But i was unable to get any resolution.
right now this is my code.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.testapp.testapp"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
splits {
abi {
enable true
reset()
include 'arm64-v8a'
universalApk true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation('me.dm7.barcodescanner:zxing:1.9') { exclude module: 'support-v4' }
implementation 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
api 'org.slf4j:slf4j-api:1.7.25'
implementation 'org.slf4j:slf4j-simple:1.7.12'
}
And also my mainactivity
public class MainPage extends AppCompatActivity {
public static NetworkParameters BTCparams = TestNet3Params.get();
public static WalletAppKit BTCkit = new WalletAppKit(BTCparams,new File("."),"BTC-Test");
static String[] account;
static String[] server;
private Handler handler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tVBTCPer = (TextView)findViewById(R.id.tVBTCPer);
TextView tVNull = (TextView)findViewById(R.id.tVNull);
tVNull.setText(System.getProperty("os.arch"));
DownloadProgressTracker BTCListener = new DownloadProgressTracker() {
#Override
public void progress(double pct, int blocksSoFar, Date date) {
tVBTCPer.setText((int) pct+"%");
}
#Override
public void doneDownload() {
tVBTCPer.setText("100%");
}
};
BTCkit.setDownloadListener(BTCListener).setBlockingStartup(false).startAsync().awaitRunning();
}
I used this library to make java applications for pc/linux and it works fine. But when im trying to compile this for android to be usable it gets hung up trying to install the apk onto my device.
my os.arch is aarch64. I also have a previous post in stackoverflow to help give it some context.
Bitcoinj library on android hung on installing APK
I am not entirely sure what library i would need to help this apk install onto my device.
I have never used any kind of JUnit before,so from what I search there is a good tool called roboelectric.
I try to run a simple test as shown in their website but the assertThat() and shadowOf() are not recognised.
Here is the test
#RunWith(RobolectricTestRunner.class)
#Config(constants = BuildConfig.class)
public class MainActivityTest {
#Test
public void clickingLogin_shouldStartLoginActivity() {
MainActivity activity = Robolectric.setupActivity(MainActivity.class);
activity.findViewById(R.id.login).performClick();
Intent expectedIntent = new Intent(activity, LoginActivity.class);
//This line doesn't work.
assertThat(shadowOf(activity).getNextStartedActivity()).
isEqualTo(expectedIntent);
}
}
And this how I set Roboelectric in gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "testing.theo.robotutorial"
minSdkVersion 14
targetSdkVersion 24
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:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
testCompile "org.robolectric:robolectric:3.0"
}
Any ideas?
Thanks.
Replace with the following assertion will work.
assertTrue(shadowOf(activity).getNextStartedActivity().filterEquals(expectedIntent));
You can refer to answer by Hoisie in Roboelectric github issue #2627 for details.
I'm new in NDK .and try to setup Integration with NDk .But after research through many sites ,i could not solved my problem. Here is build.gradle file
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
}
android.ndk {
moduleName "native"
}
defaultConfig.with {
applicationId "app.com.jnitester"
minSdkVersion.apiLevel 15
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
buildConfigFields {
create() {
type = "int"
name = "VALUE"
value = "1"
}
}
}
/* android.ndk {
moduleName = "native"
}*/
android.buildTypes {
release {
minifyEnabled false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
create("flavor1") {
applicationId "com.app"
}
}
android.sources {
main {
jni {
source {
srcDir 'src'
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
my classpath is:
classpath 'com.android.tools.build:gradle-experimental:0.4.0'
we get error like that:
Error:(18, 0) No signature of method: org.gradle.model.dsl.internal.NonTransformedModelDslBacking.applicationId() is applicable for argument types: (java.lang.String) values: [app.com.jnitester]
Open File
when i put buildTypes,productFlavours,sources inside android{} then it gives Errors like that:
Error:(4, 1) A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> Could not find method compileSdkVersion() for arguments [23] on project ':app'.
may be this question be duplicate but we couldn't find the solution yet .
Your help would save my time. Any Help would be appreciated in Advanced.
try adding '=' char. e.g.
compileSdkVersion 23
change to
compileSdkVersion = 23
I want to develop a small android library and share it later with the community. I want to use javassist, especially the project morpheus to manipulate the bytecode of annotated classes during the build time.
Currently im stuck while i want to use my TestTransformer class from the Library within the TestApplications build.gradle script. The TestTransformer.java is defined as usual within the library project.
library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.github.stephanenicolas.javassist:javassist-build-plugin-api:1.0.0'
}
application build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: 'com.android.application'
apply plugin: 'morpheus'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "example.com.testapplication"
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
//compile 'com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.8'
compile project(':testlibrary')
}
morpheus {
//transformers = new example.com.testlibrary.TestTransformer()
transformers = new com.example.testlibrary.TestTransformer()
}
TestTransformer.java
import javassist.build.IClassTransformer;
import javassist.build.JavassistBuildException;
public class TestTransformer implements IClassTransformer {
#Override
public void applyTransformations(CtClass ctClass) throws JavassistBuildException {
}
#Override
public boolean shouldTransform(CtClass ctClass) throws JavassistBuildException {
return false;
}
}
Now i get the following error when i try to sync the projects with gradle files:
Error:(44, 0) Cause: startup failed:
build file 'C:\Users\MyUser\AndroidStudioProjects\TestApplication\app\build.gradle': 44: unable to resolve class com.example.testlibrary.TestTransformer
# line 44, column 20.
transformers = new com.example.testlibrary.TestTransformer()
1 error
Is it even possible to achieve my planned propose?
Thanks alot!
I use Android Studio 1.1.0 and created a new Android project. AS creates this new project with one ApplicationTest. When I call:
$ ./gradlew clean createDebugCoverageReport
this ApplicationTest is executed. Now I added a new test:
public class ActivityTest extends ActivityInstrumentationTestCase2<MainActivity>
But this new test isn't executed. Whats going wrong? Both test classes are in the same folder:
app\src\androidTest\java\eu.the4thfloor.testapp\
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "eu.the4thfloor.testapp"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
jacoco {
version = '0.7.3.201502191951'
}
buildTypes {
debug {
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
The problem was the wrong constructor.
AS suggested this one:
public ActivityTest(Class<MainActivity> activityClass) {
super(activityClass);
}
But with this constructor the test isn't executed. You have to use this constructor:
public ActivityTest() {
super(MainActivity.class);
}
The complete test class looks like this:
import android.test.ActivityInstrumentationTestCase2;
public class ActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
public ActivityTest() {
super(MainActivity.class);
}
public void test2() {
assertTrue(true);
}
}
Give only
./gradlew test
a try.